Re: [Haskell-cafe] Is c2hs able to generate FunPtr rather than just the function?

2009-10-05 Thread Bulat Ziganshin
Hello Rafal,

Monday, October 5, 2009, 9:18:30 AM, you wrote:

 Is there a neat way to have c2hs generate the FunPtr version for me?

from my program:

-- |My callback function type
type CALLBACK_FUNC  =  Ptr CChar - IO CInt

foreign import ccall threadsafe wrapper
   mkCALL_BACK :: CALLBACK_FUNC - IO (FunPtr CALLBACK_FUNC)

key word here is wrapper in foreign import statement. read FFI specs
for that


-- 
Best regards,
 Bulatmailto:bulat.zigans...@gmail.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Curried function terminology

2009-10-05 Thread Jon Fairbairn
michael rice nowg...@yahoo.com writes:

 This is from Learn You A Haskell:

 ==

 Curried functions

 Every function in Haskell officially only takes one
 parameter. So how is it possible that we defined and used
 several functions that take more than one parameter so far?
 Well, it's a clever trick! All the functions that accepted
 several parameters so far have been curried functions. What
 does that mean? You'll understand it best on an example.
 Let's take our good friend, the max function. It looks like
 it takes two parameters and returns the one that's bigger.
 Doing max 4 5 first creates a function that takes a
 parameter and returns either 4 or that parameter, depending
 on which is bigger. Then, 5 IS APPLIED TO THAT FUNCTION and
 that function produces our desired result.

 What really happens when we do multThree 3 5 9 or
 ((multThree 3) 5) 9? First, 3 is applied to multThree,
 because they're separated by a space. That creates a
 function that takes one parameter and returns a function. So
 then 5 IS APPLIED TO THAT, which creates a function that
 will take a parameter and multiply it by 15. 9 IS APPLIED TO
 THAT FUNCTION and the result is 135 or something.

 ===

 The language (in CAPS) in the above two paragraphs seems to
 be backwards.

It is. 5 is applied to that function should be 5 is supplied to that
function (or that function is applied to 5) and so on. It's a fairly
common error in writing this sort of thing¹, and given that the title
Learn You A Haskell is totally ungrammatical, hardly seems surprising.

 In the first paragraph, since functions are
 conventionally applied to parameters shouldn't it read
 something like THE PARTIALLY APPLIED FUNCTION IS THEN
 APPLIED TO the 5? Or is the terminology different for
 Haskell, 

No, but Haskell does have a lot of non-native users of English among its
users.


[1] A pet peeve of mine is x supports y being used backwards (as in
our application supports windows Vista, which would only make sense if
it were something like a system tool that stopped Vista crashing.

-- 
Jón Fairbairn jon.fairba...@cl.cam.ac.uk
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2009-01-31)

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] dsl and gui toolkit

2009-10-05 Thread Andrew U. Frank
writing a gui is a mess (independent of wx or gtk) - too much detail is shown 
and not enough abstraction is done. haskell can help.

i have written an experimental way of producing the GUI  automatically with a 
description of the semantics of the types and operations involved (a la 
ontology, evnetually comparable what protege produces).
the input is a descriptionof the entity ypes, the fields used, the functional 
dependencies between the fiels, plus the operations used. 
the division in screens and their layout.

the rest ist automatic.
the result is a GUI (with preferably gtk but i had also a wx version running). 

the ideas were inspired by eliot conal's work and wxgeneric, which seemed for 
administrative applications either too restricted or to specific.

if somebody wants to try it out for his application, please write
fr...@geoinfo.tuwien.ac.at

(there is not much documentation and the code is not yet completely clean - 
testing by somebody else would be very valuable!)

andrew

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: dsl and gui toolkit

2009-10-05 Thread Günther Schmidt

lemme have it please!

Günther


Am 05.10.2009, 12:42 Uhr, schrieb Andrew U. Frank  
fr...@geoinfo.tuwien.ac.at:


writing a gui is a mess (independent of wx or gtk) - too much detail is  
shown

and not enough abstraction is done. haskell can help.

i have written an experimental way of producing the GUI  automatically  
with a

description of the semantics of the types and operations involved (a la
ontology, evnetually comparable what protege produces).
the input is a descriptionof the entity ypes, the fields used, the  
functional

dependencies between the fiels, plus the operations used.
the division in screens and their layout.

the rest ist automatic.
the result is a GUI (with preferably gtk but i had also a wx version  
running).


the ideas were inspired by eliot conal's work and wxgeneric, which  
seemed for

administrative applications either too restricted or to specific.

if somebody wants to try it out for his application, please write
fr...@geoinfo.tuwien.ac.at

(there is not much documentation and the code is not yet completely  
clean -

testing by somebody else would be very valuable!)

andrew


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: dsl and gui toolkit

2009-10-05 Thread Gregor Burger
hi there,
i can't resist to post grun here! although its python based
the ideas behind are great! maybe some excellent haskell
hackers can borrow some ideas from it.

http://pypi.python.org/pypi/grun/

gregor

2009/10/5 Günther Schmidt gue.schm...@web.de

 lemme have it please!

 Günther


 Am 05.10.2009, 12:42 Uhr, schrieb Andrew U. Frank 
 fr...@geoinfo.tuwien.ac.at:


  writing a gui is a mess (independent of wx or gtk) - too much detail is
 shown
 and not enough abstraction is done. haskell can help.

 i have written an experimental way of producing the GUI  automatically
 with a
 description of the semantics of the types and operations involved (a la
 ontology, evnetually comparable what protege produces).
 the input is a descriptionof the entity ypes, the fields used, the
 functional
 dependencies between the fiels, plus the operations used.
 the division in screens and their layout.

 the rest ist automatic.
 the result is a GUI (with preferably gtk but i had also a wx version
 running).

 the ideas were inspired by eliot conal's work and wxgeneric, which seemed
 for
 administrative applications either too restricted or to specific.

 if somebody wants to try it out for his application, please write
 fr...@geoinfo.tuwien.ac.at

 (there is not much documentation and the code is not yet completely clean
 -
 testing by somebody else would be very valuable!)

 andrew


 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: dsl and gui toolkit

2009-10-05 Thread Alp Mestan
It'd be great if you could at least paste some sample lines of usage
of your library.

On 10/5/09, Gregor Burger burger.gre...@gmail.com wrote:
 hi there,
 i can't resist to post grun here! although its python based
 the ideas behind are great! maybe some excellent haskell
 hackers can borrow some ideas from it.

 http://pypi.python.org/pypi/grun/

 gregor

 2009/10/5 Günther Schmidt gue.schm...@web.de

 lemme have it please!

 Günther


 Am 05.10.2009, 12:42 Uhr, schrieb Andrew U. Frank 
 fr...@geoinfo.tuwien.ac.at:


  writing a gui is a mess (independent of wx or gtk) - too much detail is
 shown
 and not enough abstraction is done. haskell can help.

 i have written an experimental way of producing the GUI  automatically
 with a
 description of the semantics of the types and operations involved (a la
 ontology, evnetually comparable what protege produces).
 the input is a descriptionof the entity ypes, the fields used, the
 functional
 dependencies between the fiels, plus the operations used.
 the division in screens and their layout.

 the rest ist automatic.
 the result is a GUI (with preferably gtk but i had also a wx version
 running).

 the ideas were inspired by eliot conal's work and wxgeneric, which
 seemed
 for
 administrative applications either too restricted or to specific.

 if somebody wants to try it out for his application, please write
 fr...@geoinfo.tuwien.ac.at

 (there is not much documentation and the code is not yet completely
 clean
 -
 testing by somebody else would be very valuable!)

 andrew


 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




-- 
Alp Mestan
http://alpmestan.wordpress.com/
http://alp.developpez.com/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Sönke Hahn
Hi!

I often stumble upon 2- (or 3-) dimensional numerical data types like

(Double, Double)

or similar self defined ones. I like the idea of creating instances for Num for 
these types. The meaning of (+), (-) and negate is clear and very intuitive, i 
think. I don't feel sure about (*), abs, signum and fromInteger. I used to 
implement

fromInteger n = (r, r) where r = fromInteger n

, but thinking about it, 

fromInteger n = (fromInteger n, 0)

seems very reasonable, too. 

Any thoughts on that? How would you do it?

btw: These are two examples i looked at in hackage:
Data.Complex.Complex (which is special, cause it is mathematically defined, 
what (*), abs, signum and fromInteger should do (i think))

and

Physics.Hipmunk.Common.Vector 
(http://hackage.haskell.org/packages/archive/Hipmunk/5.0.0/doc/html/Physics-
Hipmunk-Common.html#9)


Sönke
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Job Vranish
You are in luck!

Such an instance is very simple with Applicative. If the type you want a Num
instance for is a member of the Applicative type class you can define it
like this:

instance (Num a) = Num (Vector2 a) where
  a + b = pure (+) * a * b
  a - b = pure (-) * a * b
  a * b = pure (*) * a * b
  negate a = pure negate * a
  abs a = pure abs * a
  signum = fmap signum
  fromInteger = pure . fromInteger

If you want to define a Num instance for _all_ applicatives, you can do this
(you'll need a couple extensions):

instance (Num a, Applicative f, Eq (f a), Show (f a)) = Num (f a) where
  a + b = pure (+) * a * b
  a - b = pure (-) * a * b
  a * b = pure (*) * a * b
  negate a = pure negate * a
  abs a = pure abs * a
  signum = fmap signum
  fromInteger = pure . fromInteger

I am currently working on a vector and matrix library for haskell that uses
instances of this form, which you can find here:
http://github.com/jvranish/VectorMatix.  The matrix half is very unfinished,
but the vector half is pretty much done.

Applicative is a pretty fantastic typeclass, it's definitly worth the time
to figure out how it works.

However, this technique won't work with tuples as they don't behave as
Functors in the way you would like. (too many type parameters, tuples don't
force all elements to be the same type so maps don't work, etc...)

Hope that helps :)

- Job



On Mon, Oct 5, 2009 at 8:40 AM, Sönke Hahn sh...@cs.tu-berlin.de wrote:

 Hi!

 I often stumble upon 2- (or 3-) dimensional numerical data types like

(Double, Double)

 or similar self defined ones. I like the idea of creating instances for Num
 for
 these types. The meaning of (+), (-) and negate is clear and very
 intuitive, i
 think. I don't feel sure about (*), abs, signum and fromInteger. I used to
 implement

fromInteger n = (r, r) where r = fromInteger n

 , but thinking about it,

fromInteger n = (fromInteger n, 0)

 seems very reasonable, too.

 Any thoughts on that? How would you do it?

 btw: These are two examples i looked at in hackage:
 Data.Complex.Complex (which is special, cause it is mathematically defined,
 what (*), abs, signum and fromInteger should do (i think))

 and

 Physics.Hipmunk.Common.Vector
 (
 http://hackage.haskell.org/packages/archive/Hipmunk/5.0.0/doc/html/Physics-
 Hipmunk-Common.html#9http://hackage.haskell.org/packages/archive/Hipmunk/5.0.0/doc/html/Physics-%0AHipmunk-Common.html#9
 )


 Sönke
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Miguel Mitrofanov



Sönke Hahn wrote:


I used to implement

fromInteger n = (r, r) where r = fromInteger n

, but thinking about it, 


fromInteger n = (fromInteger n, 0)

seems very reasonable, too. 


Stop pretending something is a number when it's not.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Curried function terminology

2009-10-05 Thread Daniel Fischer
Am Montag 05 Oktober 2009 11:52:17 schrieb Jon Fairbairn:
 michael rice nowg...@yahoo.com writes:
  This is from Learn You A Haskell:
snip
  The language (in CAPS) in the above two paragraphs seems to
  be backwards.

 It is. 5 is applied to that function should be 5 is supplied to that
 function (or that function is applied to 5) and so on. It's a fairly
 common error in writing this sort of thing¹, and given that the title
 Learn You A Haskell is totally ungrammatical, hardly seems surprising.

  In the first paragraph, since functions are
  conventionally applied to parameters shouldn't it read
  something like THE PARTIALLY APPLIED FUNCTION IS THEN
  APPLIED TO the 5? Or is the terminology different for
  Haskell,

That would be correct but awkward. 
IMO it would be better to say that 5 is then supplied (or fed) to (the 
partially applied 
function).
I tend to feed arguments to functions if I don't want to apply a function to an 
argument.


 No, but Haskell does have a lot of non-native users of English among its
 users.

I'm not sure that's relevant for this kind of error. I think it's more a lack 
of 
familiarity with mathematical terminology.


 [1] A pet peeve of mine is x supports y being used backwards (as in
 our application supports windows Vista, which would only make sense if
 it were something like a system tool that stopped Vista crashing.

Or if Microsoft uses the profits from App X to compensate deficits incurred by 
Vista.
Or if the application sports banners Vista is great! Get you a Vista today! :D

But seriously, yes, it's annoying.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread John A. De Goes


That's not gonna happen until when/if Haskell supports name/operator  
overloading. There's a scarcity of good symbols/function names and  
everyone wants to use them. So naturally, type class abuse follows.


Regards,

John A. De Goes
N-Brain, Inc.
The Evolution of Collaboration

http://www.n-brain.net|877-376-2724 x 101

On Oct 5, 2009, at 7:12 AM, Miguel Mitrofanov wrote:




Sönke Hahn wrote:


I used to implement
   fromInteger n = (r, r) where r = fromInteger n
, but thinking about it, fromInteger n = (fromInteger n, 0)
seems very reasonable, too.


Stop pretending something is a number when it's not.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] I/O Haskell question

2009-10-05 Thread Maria Boghiu
Hey.

I'm trying to configure Xmonad, the window manager.

for this purpose, I'm trying to read the *workspaces* variable in the code
below from file.
As you can see, I do workspaces = readWS where
*
readWS = do
 l - readFile ~/bla
 return l*

I get an error saying I am mismatching types IO [String] and [String].
But I thought that once one does * l - readFile ~/bla*, l is the a string
or, in this case, a String list. If I run that line in prelude it seems to
be working fine, prints the content of the file ~/bla on screen (though
I'm not sure if as a String or as a list of Strings, i.e. [String])

Can anyone help please?
I've been struggling with this for days...

94 main = do
 95 xmonad
 96 $ defaultConfig {
 97 manageHook = manageDocks + myManageHook + manageHook
defaultConfig,
 98 layoutHook = avoidStruts $ layoutHook defaultConfig,
 99 logHook= dynamicLogWithPP $ conkyPP ,
100 terminal   = gnome-terminal,
101 keys   = myKeys,
102 workspaces = readWS,
103 mouseBindings  = myMouseBindings,
104 focusedBorderColor = #008E00,
105 borderWidth= 3
106 --modMask= mod1Mask, --This is to rebind mod key
107 } `additionalKeys`
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Lennart Augustsson
And what is a number?  Are complex numbers numbers?

On Mon, Oct 5, 2009 at 3:12 PM, Miguel Mitrofanov miguelim...@yandex.ru wrote:


 Sönke Hahn wrote:

 I used to implement

    fromInteger n = (r, r) where r = fromInteger n

 , but thinking about it,
    fromInteger n = (fromInteger n, 0)

 seems very reasonable, too.

 Stop pretending something is a number when it's not.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] I/O Haskell question

2009-10-05 Thread Deniz Dogan
2009/10/5 Maria Boghiu maria.bog...@gmail.com:
 I get an error saying I am mismatching types IO [String] and [String].

Something of the type IO [String] is a computation which does some IO
(reading files, launching nukes, etc.) and then returns a list of
strings. Something of the type [String] is merely a list of strings.
It is impossible (I'm lying here, but for a good cause) to convert
something on the form IO a to just a.

Try something like this:

main = do
  fileContent - readFile /path/to/file
  xmonad $ defaultConfig {
...
workspaces = lines fileContent,
...
  } ...

-- 
Deniz Dogan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ICFP videos now available

2009-10-05 Thread Wouter Swierstra
I am happy to announce that videos of all talks at ICFP and some of
the associated workshops this year have made available online:

  http://www.vimeo.com/user2191865/albums

I'm sure you'll join me in thanking Malcolm Wallace for the time and
effort he put into making this possible. Thank you Malcolm!

  Wouter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Designing a DSL?

2009-10-05 Thread S. Doaitse Swierstra



On 2 okt 2009, at 20:37, Jake McArthur wrote:


Günther Schmidt wrote:
And that I find to be the really tricky part, how do I *design* a  
DSL?


I once wrote a tutorial on this subject in which I explain that  
designing a DSL is not so much different from an ordinary programming  
language; the only difference is that you do not have to think about  
type systems and abstraction mechanisms. The tutorial can be found in:



@inproceedings{SwieAzSar98Braga,
	Author = {Swierstra, S. Doaitse and Azero~Alcocer, Pablo R. and  
Saraiva, Jo{\~a}o A.},
	Booktitle = {Advanced Functional Programming, Third International  
School, AFP'98},

Date-Added = {2008-07-15 17:22:15 +0200},
Date-Modified = {2009-01-16 17:35:05 +0100},
	Editor = {Swierstra, S. D. and Henriques, Pedro and Oliveira, Jos 
\'{e}},

Pages = {150-206},
Publisher = {Springer-Verlag},
Series = {LNCS},
Title = {Designing and Implementing Combinator Languages},
Volume = {1608},
Year = {1999}}

It basically describes the origins of the Utrecht Attribute Grammar  
System, uuagc, available from hackage; the basic message is that when  
you implement a language you use compiler construction tools! An  
example of this can be found in a paper Olaf Chitil and I recently  
published in the JFP:



@article{CambridgeJournals:2837460,
Author = {SWIERSTRA, S. DOAITSE and CHITIL, OLAF},
Date-Added = {2009-02-13 10:17:23 +0100},
Date-Modified = {2009-02-13 10:17:23 +0100},
Doi = {10.1017/S0956796808006990},
Eprint = {http://journals.cambridge.org/article_S0956796808006990},
Journal = {Journal of Functional Programming},
Number = {01},
Pages = {1-16},
Title = {Linear, bounded, functional pretty-printing},
	Url = {http://journals.cambridge.org/action/displayAbstract?fromPage=onlineaid=2837460fulltextType=RCfileId=S0956796808006990 
},

Volume = {19},
Year = {2009},
	Abstract = { ABSTRACT We present two implementations of Oppen's  
pretty-printing algorithm in Haskell that meet the efficiency of  
Oppen's imperative solution but have a simpler and a clear structure.  
We start with an implementation that uses lazy evaluation to simulate  
two co-operating processes. Then we present an implementation that  
uses higher-order functions for delimited continuations to simulate co- 
routines with explicit scheduling. },
	Bdsk-Url-1 = {http://journals.cambridge.org/action/displayAbstract?fromPage=onlineaid=2837460fulltextType=RCfileId=S0956796808006990 
},

Bdsk-Url-2 = {http://dx.doi.org/10.1017/S0956796808006990}}

This paper describes two implementation of a functional pretty  
printing, finally solving the problem how to do so with limited alook- 
ahead, as in Oppen's orginal paper. One of the solutions was created  
using an attribute grammar way of thinking and the attribute grammar  
can be found at the end of the technical report, and I hope that this  
example convinces you of the elegance of this approach:



@techreport{PPTr2004,
Author = {Swierstra, S.D.},
Date-Added = {2009-01-04 17:21:54 +0100},
Date-Modified = {2009-01-04 17:21:54 +0100},
Institution = {Inst. of Information and Comp. Science, Utrecht Univ.},
Note = {submitted for publication},
Number = {UU-CS-2004-025a},
Pubcat = {techreport},
	Title = {Linear, Online, Functional Pretty printing (extended and  
corrected version)},
	Urlpdf = {{http://archive.cs.uu.nl/pub/RUU/CS/techreps/CS-2004/2004-025a.pdf 
}},

Year = 2004}

In a more abstract setting your question is also How do I design a  
library, How do I design a consistent theory, and How do I model  
something. These questions are harder to answer ;-}


 Doaitse Swierstra





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] dsl and gui toolkit

2009-10-05 Thread Jake McArthur
If you could throw it on Hackage or a public repo you will get more 
exposure. :)


- Jake
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread jerzy . karczmarczuk

Miguel Mitrofanov rebukes Sönke Hahn, who -:


 wrote:

I used to implement
fromInteger n = (r, r) where r = fromInteger n
, but thinking about it, 
fromInteger n = (fromInteger n, 0)

seems very reasonable, too.




Stop pretending something is a number when it's not.


Miguel Mitrofanov, please kindly stop pretending that you KNOW
what is a number, and what is not.

The numeric classes in standard Haskell are disgraceful, and the idea
that if something can be added, it is a number is bad. Vectors are not
numbers, but inventing special (+) for all kinds of Abelian additions
is awkward. So, people call numbers what they wish, and it is *their*
business. I needed to add functions (of course, without Eq nor Show
membership), I had to fake... Pairs (a,b) may be numbers in various
contexts, for example (value,derivative) in automatic differentiation. Or
(mainTerm,otherOrders) in some infinitesimal calculus. Or pairs (scalar,
3vector) for quaternions. 


The idea of putting fromInteger in the same class, is a design bug
(my personal opinion, of course). There are plenty of examples where
conversions from integers are legitimate, but no addition or (*)seem
natural. Or the other way round ; apparently Sönke Hahn is in that
situation, so he fakes...

Jerzy Karczmarczuk
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] better way to do this?

2009-10-05 Thread Michael Mossey



Eugene Kirpichov wrote:

[x,y,t,b,l,r] - mapM (getStdRandom . randomR) [(-10,10), (-70,70), ...]
return (BoxBounds ...)


Thanks.

I'm curious about the idea of pattern matching in do-statements that can 
fail. This particular pattern cannot fail. I read that the fail function 
was introduced to Monad in order to handle pattern matches that fail, and 
that most members of haskell-cafe seem to think that was a mistake---that 
MonadZero should have been used instead. I.e., any do-block with a pattern 
that can fail should explicitly have a MonadZero class constraint.


This leads to my question about detecting pattern matches that could fail. 
We can easily prove the above pattern will never fail. I'm wondering if the 
compiler infers this. And if a future version of Haskell dumps fail and 
used MonadZero to replace it, would that future Haskell compiler need to 
infer, in all cases, whether a pattern can fail? Is it simple enough to 
make that correct inference?


Thanks,
Mike
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] better way to do this?

2009-10-05 Thread Michael Mossey
If I understand correctly, this works because IO is an instance of 
Applicative, correct?


I wonder if any of the random monads are instances of Applicative.

Felipe Lessa wrote:

On Sun, Oct 04, 2009 at 01:55:11PM +0400, Eugene Kirpichov wrote:

[x,y,t,b,l,r] - mapM (getStdRandom . randomR) [(-10,10), (-70,70), ...]
return (BoxBounds ...)


import Control.Applicative

let f = getStdRandom . randomR
g1 = \x - f (-x,x)
g2 = f (5,10)
in BoxBounds $ g1 10 * g1 70 * g2 * g2 * g2 * g2

--
Felipe.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] better way to do this?

2009-10-05 Thread Eugene Kirpichov
2009/10/5 Michael Mossey m...@alumni.caltech.edu:


 Eugene Kirpichov wrote:

 [x,y,t,b,l,r] - mapM (getStdRandom . randomR) [(-10,10), (-70,70), ...]
 return (BoxBounds ...)

 Thanks.

 I'm curious about the idea of pattern matching in do-statements that can
 fail. This particular pattern cannot fail. I read that the fail function
 was introduced to Monad in order to handle pattern matches that fail, and
 that most members of haskell-cafe seem to think that was a mistake---that
 MonadZero should have been used instead. I.e., any do-block with a pattern
 that can fail should explicitly have a MonadZero class constraint.

 This leads to my question about detecting pattern matches that could fail.
 We can easily prove the above pattern will never fail. I'm wondering if the
 compiler infers this.

Try proving it by hand and judge the result with respect to whether it
could have been done by the compiler.

 And if a future version of Haskell dumps fail and
 used MonadZero to replace it, would that future Haskell compiler need to
 infer, in all cases, whether a pattern can fail? Is it simple enough to make
 that correct inference?

 Thanks,
 Mike
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




-- 
Eugene Kirpichov
Web IR developer, market.yandex.ru
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] I/O Haskell question

2009-10-05 Thread Keith Sheppard
I have to nominate I'm lying here, but for a good cause as a quote
of the week.

-Keith

On Mon, Oct 5, 2009 at 10:06 AM, Deniz Dogan deniz.a.m.do...@gmail.com wrote:
 2009/10/5 Maria Boghiu maria.bog...@gmail.com:
 I get an error saying I am mismatching types IO [String] and [String].

 Something of the type IO [String] is a computation which does some IO
 (reading files, launching nukes, etc.) and then returns a list of
 strings. Something of the type [String] is merely a list of strings.
 It is impossible (I'm lying here, but for a good cause) to convert
 something on the form IO a to just a.

 Try something like this:

 main = do
  fileContent - readFile /path/to/file
  xmonad $ defaultConfig {
    ...
    workspaces = lines fileContent,
    ...
  } ...

 --
 Deniz Dogan
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




-- 
keithsheppard.name
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Curried function terminology

2009-10-05 Thread michael rice
Yeah, and Haskell supports Linux, AND Windows. ;-)



Thanks for the explanation. My shorts weren't in a knot; just said Huh?
upon reading it, thinking maybe I misunderstood something along the way.



Michael


--- On Mon, 10/5/09, Jon Fairbairn jon.fairba...@cl.cam.ac.uk wrote:

From: Jon Fairbairn jon.fairba...@cl.cam.ac.uk
Subject: [Haskell-cafe] Re: Curried function terminology
To: haskell-cafe@haskell.org
Date: Monday, October 5, 2009, 5:52 AM

michael rice nowg...@yahoo.com writes:

 This is from Learn You A Haskell:

 ==

 Curried functions

 Every function in Haskell officially only takes one
 parameter. So how is it possible that we defined and used
 several functions that take more than one parameter so far?
 Well, it's a clever trick! All the functions that accepted
 several parameters so far have been curried functions. What
 does that mean? You'll understand it best on an example.
 Let's take our good friend, the max function. It looks like
 it takes two parameters and returns the one that's bigger.
 Doing max 4 5 first creates a function that takes a
 parameter and returns either 4 or that parameter, depending
 on which is bigger. Then, 5 IS APPLIED TO THAT FUNCTION and
 that function produces our desired result.

 What really happens when we do multThree 3 5 9 or
 ((multThree 3) 5) 9? First, 3 is applied to multThree,
 because they're separated by a space. That creates a
 function that takes one parameter and returns a function. So
 then 5 IS APPLIED TO THAT, which creates a function that
 will take a parameter and multiply it by 15. 9 IS APPLIED TO
 THAT FUNCTION and the result is 135 or something.

 ===

 The language (in CAPS) in the above two paragraphs seems to
 be backwards.

It is. 5 is applied to that function should be 5 is supplied to that
function (or that function is applied to 5) and so on. It's a fairly
common error in writing this sort of thing¹, and given that the title
Learn You A Haskell is totally ungrammatical, hardly seems surprising.

 In the first paragraph, since functions are
 conventionally applied to parameters shouldn't it read
 something like THE PARTIALLY APPLIED FUNCTION IS THEN
 APPLIED TO the 5? Or is the terminology different for
 Haskell, 

No, but Haskell does have a lot of non-native users of English among its
users.


[1] A pet peeve of mine is x supports y being used backwards (as in
our application supports windows Vista, which would only make sense if
it were something like a system tool that stopped Vista crashing.

-- 
Jón Fairbairn                                 jon.fairba...@cl.cam.ac.uk
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2009-01-31)

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



  ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Job Vranish
In what way is it not a number?

data MyNumber a = MyNum a a
   deriving (Show, Eq)

instance Functor MyNum where
  fmap f (MyNum a b) = MyNum (f a) (f b)

instance Applicative MyNum where
  pure a = MyNum a a
  MyNum f g * MyNum a b = MyNum (f a) (g b)

instance (Num a) = Num (MyNum a) where
  a + b = pure (+) * a * b
  a - b = pure (-) * a * b
  a * b = pure (*) * a * b
  negate a = pure negate * a
  abs a = pure abs * a
  signum = fmap signum
  fromInteger = pure . fromInteger

This instance obeys the commutative, distributive, and associative laws,
and the multiplicative, and additive identities. (at least, if the numbers
it contains satisfy those laws)
How is MyNum not a number?


Sönke Hahn:
  btw, I forgot to mention in my first email, but
  fromInteger n = (r, r) where r = fromInteger n
  is better than:
  fromInteger n = (fromInteger n, 0)
 as you get a lot of corner cases otherwise.

 I use fromInteger = pure . fromInteger, which when combined with my
Applicative instance, is effectively the same as your:  fromInteger n = (r,
r) where r = fromInteger n


- Job

On Mon, Oct 5, 2009 at 9:12 AM, Miguel Mitrofanov miguelim...@yandex.ruwrote:



 Sönke Hahn wrote:

  I used to implement

fromInteger n = (r, r) where r = fromInteger n

 , but thinking about it,
fromInteger n = (fromInteger n, 0)

 seems very reasonable, too.


 Stop pretending something is a number when it's not.

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] apply function arguments in a list

2009-10-05 Thread Michael Mossey
If I have a list containing the arguments I want to give to a function, is 
there a general way to supply those arguments in a compact syntax?


In other words, I could have

args = [1,2,3]
f x y z = ...

I would write

t = f (args!!0) (args!!1) (args!!2)

but there may be a neater, more general syntax. I tried writing a fold with 
$, but I don't think that works because the type of each step is different. 
I.e.


f :: a - a - a - a
f x :: a - a - a
f x y :: a - a
f x y z :: a

This would seem to preclude a general way of writing a function that 
supplies arguments from a list.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] I/O Haskell question

2009-10-05 Thread Gwern Branwen

On Mon, Oct 5, 2009 at 9:48 AM, Maria Boghiu maria.bog...@gmail.com wrote:

Hey.

I'm trying to configure Xmonad, the window manager.

for this purpose, I'm trying to read the workspaces variable in the code
below from file.
As you can see, I do workspaces = readWS where

readWS = do
 l - readFile ~/bla
 return l

I get an error saying I am mismatching types IO [String] and [String].
But I thought that once one does l - readFile ~/bla, l is the a string
or, in this case, a String list. If I run that line in prelude it seems to
be working fine, prints the content of the file ~/bla on screen (though
I'm not sure if as a String or as a list of Strings, i.e. [String])

Can anyone help please?
I've been struggling with this for days...

94 main = do
 95 xmonad
 96 $ defaultConfig {
 97 manageHook = manageDocks + myManageHook + manageHook
defaultConfig,
 98 layoutHook = avoidStruts $ layoutHook defaultConfig,
 99 logHook    = dynamicLogWithPP $ conkyPP ,
100 terminal   = gnome-terminal,
101 keys   = myKeys,
102 workspaces = readWS,
103 mouseBindings  = myMouseBindings,
104 focusedBorderColor = #008E00,
105 borderWidth    = 3
106 --modMask    = mod1Mask, --This is to rebind mod key
107 } `additionalKeys`


A quick tip: when GHC gives you a compile error like that, it's because you've 
made an error where 'what I say' is not 'what I [want to] do'. In this case, 
you're *saying* 'use readFile, which returns a String', and *doing* 'ok, here, 
use this [String]'.

The way to know that it's an issue is to find out what type readFile is; in ghci you 
can do ':type readFile' and it'll tell you String - IO String. Now you know 
workspaces needs [String], so you need something which goes 'String - [String]'. 
If you don't already know that that is 'lines', then you can ask Hoogle 
http://www.haskell.org/hoogle/  that question: 
http://www.haskell.org/hoogle/?hoogle=String+-%3E+[String] and it will give you as 
the first hit exactly what you need. (Hoogle is great for beginners who don't know 
the libraries.)

Obviously, this is a real issue; there's no way the compiler could possibly figure 
out what the right thing to do because there are so many ways to do 
String-[String] (just consider the specific example of 'lines' - how does it 
handle Windows v Unix line-endings?). So you have to tell it.

The monad issue with the difference between IO [String] and [String] I will 
leave to others to explain. :)

--
gwern

signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Miguel Mitrofanov

Miguel Mitrofanov, please kindly stop pretending that you KNOW
what is a number, and what is not.


Never said that. Sometimes it's debatable. But if you can't figure out a 
way to multiply things so that it would make some kind of sense - you 
haven't made them numbers (yet).



The numeric classes in standard Haskell are disgraceful, and the idea
that if something can be added, it is a number is bad.


Which is kinda my point.


So, people call numbers what they wish, and it is *their* business.


I'm not sure what do you mean here.

Of course, it's OK to call anything numbers provided that you stated 
explicitly what exactly you would mean by that. But then you have to 
drop all kind of stuff mathematicians developed for the usual notion of 
numbers. In the same way, you shouldn't use the Num class for your 
numbers.


On the other hand, people can (ab)use the Num class as they wish, and 
it's their business until they ask a question about it somewhere outside 
- which makes the business not only theirs.



Pairs (a,b) may be numbers in various contexts, for example
 (value,derivative) in automatic differentiation. Or 
(mainTerm,otherOrders)
 in some infinitesimal calculus. Or pairs (scalar, 3vector) for 
quaternions.


Or (real, imaginary) for complex numbers. That's right. All these 
notions are very different - which is why pairs of numbers are NOT 
numbers - but complex numbers are, as well as value-derivative pairs.


Isn't that what we have newtypes for?


There are plenty of examples where conversions from integers are legitimate,

 but no addition or (*)seem natural.

Certainly. I think it's commonplace that numerical classes in Haskell 
Prelude are not exactly an example of perfect design.


Still, it doesn't make it good to abuse classes like Num just because 
we want a fancy plus sign.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] apply function arguments in a list

2009-10-05 Thread Miguel Mitrofanov

t = let [x,y,z] = args in f x y z

Michael Mossey wrote:

t = f (args!!0) (args!!1) (args!!2)


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Miguel Mitrofanov

Lennart Augustsson wrote:

And what is a number?


Can't say. You know, it's kinda funny to ask a biologist what it means 
to be alive.



Are complex numbers numbers?


Beyond any reasonable doubt. Just like you and me are most certainly alive.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] apply function arguments in a list

2009-10-05 Thread Neil Brown

Michael Mossey wrote:
If I have a list containing the arguments I want to give to a 
function, is there a general way to supply those arguments in a 
compact syntax?


In other words, I could have

args = [1,2,3]
f x y z = ...

I would write

t = f (args!!0) (args!!1) (args!!2)

but there may be a neater, more general syntax.
In general, the problem is that you can't guarantee ahead of time that 
the list will have three elements, so however you write it, you'll turn 
a compile-time error (wrong number of args to function) into a run-time 
error (!! says index is invalid).  The neatest way is probably:


t [x,y,z] = f x y z

Which will give a slightly better error if the list is the wrong size.  
If your function takes many arguments of the same type, perhaps you 
could generalise it to take a list of arbitrary size, and do away with 
requiring three arguments?  Alternatively, use tuples if you want an 
easy way to carry the arguments around together:


args = (1, 2, 3)
f x y z = ...

uncurry3 f (x,y,z) = f x y z

t = uncurry3 f

(uncurry already exists, I think uncurry3 is one you have to add yourself).

Neil.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Lennart Augustsson
But complex numbers are just pairs of numbers.  So pairs of numbers
can obviously be numbers then.

On Mon, Oct 5, 2009 at 4:40 PM, Miguel Mitrofanov miguelim...@yandex.ru wrote:
 Lennart Augustsson wrote:

 And what is a number?

 Can't say. You know, it's kinda funny to ask a biologist what it means to be
 alive.

 Are complex numbers numbers?

 Beyond any reasonable doubt. Just like you and me are most certainly alive.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] better way to do this?

2009-10-05 Thread Daniel Fischer
Am Montag 05 Oktober 2009 16:22:15 schrieb Michael Mossey:
 Eugene Kirpichov wrote:
  [x,y,t,b,l,r] - mapM (getStdRandom . randomR) [(-10,10), (-70,70), ...]
  return (BoxBounds ...)

 Thanks.

 I'm curious about the idea of pattern matching in do-statements that can
 fail. This particular pattern cannot fail.

It can. It won't fail in this particular context, but it's a refutable pattern, 
that's 
what counts.

Whether or not a pattern matching in a do-block can fail is intrinsic to the 
pattern.

 I read that the fail function
 was introduced to Monad in order to handle pattern matches that fail, and
 that most members of haskell-cafe seem to think that was a mistake---that
 MonadZero should have been used instead. I.e., any do-block with a pattern
 that can fail should explicitly have a MonadZero class constraint.

 This leads to my question about detecting pattern matches that could fail.
 We can easily prove the above pattern will never fail.

We can. And we could make the compiler able to prove it, too.

 I'm wondering if the compiler infers this.

Not worth the hassle.
One could make the compiler infer any finite number of special cases, but you 
can't have 
an algorithm that can for an arbitrary refutable pattern and an arbitrary 
monadic action 
(of appropriate type) decide whether the pattern match in

pat - act

will always succeed.

 And if a future version of
 Haskell dumps fail and used MonadZero to replace it, would that
 future Haskell compiler need to infer, in all cases, whether a pattern
 can fail? Is it simple enough to make that correct inference?

Using a refutable pattern would add the MonadZero constraint, while do-blocks 
with only 
irrefutable patterns can be had in any Monad.

Whether a pattern is refutable or irrefutable is easy to decide (cf. 
http://haskell.org/onlinereport/exps.html#sect3.17).


 Thanks,
 Mike

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Brad Larsen
On Mon, Oct 5, 2009 at 10:36 AM, Miguel Mitrofanov
miguelim...@yandex.ru wrote:
[...]
 Of course, it's OK to call anything numbers provided that you stated
 explicitly what exactly you would mean by that. But then you have to drop
 all kind of stuff mathematicians developed for the usual notion of numbers.
 In the same way, you shouldn't use the Num class for your numbers.

 On the other hand, people can (ab)use the Num class as they wish, and it's
 their business until they ask a question about it somewhere outside - which
 makes the business not only theirs.
[...]

The Num class has `negate' as part of its definition.  Natural numbers
are numbers, but I don't believe there is any sensible definition of
`negate' for them.

Haskell 98's numeric hierarchy combines many operations which should
be separate.  As further evidence, every bit of Haskell I have seen
that does symbolic manipulation of numeric expressions either leaves
out instances that would make the syntax more convenient, or else
defines partial instances because certain class functions have no
sensible definition for symbolic expressions.

Sincerely,
Brad
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Lennart Augustsson
Everyone agrees that the Haskell numeric hierarchy is flawed, but I've
yet to see a good replacement.

On Mon, Oct 5, 2009 at 4:51 PM, Brad Larsen brad.lar...@gmail.com wrote:
 On Mon, Oct 5, 2009 at 10:36 AM, Miguel Mitrofanov
 miguelim...@yandex.ru wrote:
 [...]
 Of course, it's OK to call anything numbers provided that you stated
 explicitly what exactly you would mean by that. But then you have to drop
 all kind of stuff mathematicians developed for the usual notion of numbers.
 In the same way, you shouldn't use the Num class for your numbers.

 On the other hand, people can (ab)use the Num class as they wish, and it's
 their business until they ask a question about it somewhere outside - which
 makes the business not only theirs.
 [...]

 The Num class has `negate' as part of its definition.  Natural numbers
 are numbers, but I don't believe there is any sensible definition of
 `negate' for them.

 Haskell 98's numeric hierarchy combines many operations which should
 be separate.  As further evidence, every bit of Haskell I have seen
 that does symbolic manipulation of numeric expressions either leaves
 out instances that would make the syntax more convenient, or else
 defines partial instances because certain class functions have no
 sensible definition for symbolic expressions.

 Sincerely,
 Brad
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Miguel Mitrofanov

No, they aren't. They are polynomials in one variable i modulo i^2+1.

Seriously, if you say complex numbers are just pairs of real numbers - 
you have to agree that double numbers (sorry, don't know the exact 
English term), defined by


(a,b)+(c,d) = (a+c,b+d)
(a,b)(c,d) = (ac, ad+bc)

are just pairs of real numbers too. After that, you have two choices: a) 
admit that complex numbers and double numbers are the same - and most 
mathematicians would agree they aren't - or b) admit that the relation 
be the same is not transitive - which is simply bizarre.



Lennart Augustsson wrote:

But complex numbers are just pairs of numbers.  So pairs of numbers
can obviously be numbers then.

On Mon, Oct 5, 2009 at 4:40 PM, Miguel Mitrofanov miguelim...@yandex.ru wrote:

Lennart Augustsson wrote:

And what is a number?

Can't say. You know, it's kinda funny to ask a biologist what it means to be
alive.


Are complex numbers numbers?

Beyond any reasonable doubt. Just like you and me are most certainly alive.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Daniel Fischer
Am Montag 05 Oktober 2009 16:29:02 schrieb Job Vranish:
 In what way is it not a number?


If there's a natural[1] implementation of fromInteger, good.
If there isn't, *don't provide one*. 
fromInteger _ = error Not sensible is better than doing something strange.

[1] In the case of residue class rings, you may choose between restricting the 
range of 
legitimate arguments for fromInteger or doing a modulo operation on the 
argument, both 
ways are natural and meet expectations sufficiently well.



 Sönke Hahn:
   btw, I forgot to mention in my first email, but
   fromInteger n = (r, r) where r = fromInteger n
   is better than:
   fromInteger n = (fromInteger n, 0)
  as you get a lot of corner cases otherwise.

  I use fromInteger = pure . fromInteger, which when combined with my
 Applicative instance, is effectively the same as your:  fromInteger n = (r,
 r) where r = fromInteger n


 - Job

 On Mon, Oct 5, 2009 at 9:12 AM, Miguel Mitrofanov 
 miguelim...@yandex.ruwrote:
  Sönke Hahn wrote:
 
   I used to implement
 
 fromInteger n = (r, r) where r = fromInteger n
 
  , but thinking about it,
 fromInteger n = (fromInteger n, 0)
 
  seems very reasonable, too.
 
  Stop pretending something is a number when it's not.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Joe Fredette
Shouldn't the question not be Is this a number? but rather What is  
a number? -- I mean, from an abstract point of view, there's really  
no such thing, right? We have sets of things which we define an  
operation that has certain properties, and suddenly we start calling  
them numbers. Are the Symmetric groups -- which you can multiply and  
divide, but not add -- numbers? If they aren't, why should Z_n be  
numbers?


What _is_ true, is that you can define a notion of addition and  
multiplication for both complexes and 'double' numbers, that doesn't  
mean they are numbers, rather, it means they are both Rings. Nor  
does it imply that they must be the same They are both rings over  
the same set of elements (Lets say, RxR), but with different operations.


Furthermore, can't you construct the Rational's from the Integers in a  
similar way as you construct the complexes from the reals (by modding  
out an ideal/polynomial (resp)) -- I actually don't know for certain,  
we haven't gotten that far in my Alg. Class yet. :), but my intuition  
says that it's likely possible.


Point is -- there are lots of classes for which you can implement a  
useful notion of addition in more than one way -- or a useful notion  
of some other class function (monad stuff for Lists and Ziplists, for  
example), but that doesn't necessarily mean that the two things are  
the same structure, right?


/Joe

On Oct 5, 2009, at 10:55 AM, Miguel Mitrofanov wrote:

No, they aren't. They are polynomials in one variable i modulo  
i^2+1.


Seriously, if you say complex numbers are just pairs of real numbers  
- you have to agree that double numbers (sorry, don't know the exact  
English term), defined by


(a,b)+(c,d) = (a+c,b+d)
(a,b)(c,d) = (ac, ad+bc)

are just pairs of real numbers too. After that, you have two  
choices: a) admit that complex numbers and double numbers are the  
same - and most mathematicians would agree they aren't - or b) admit  
that the relation be the same is not transitive - which is simply  
bizarre.



Lennart Augustsson wrote:

But complex numbers are just pairs of numbers.  So pairs of numbers
can obviously be numbers then.
On Mon, Oct 5, 2009 at 4:40 PM, Miguel Mitrofanov miguelim...@yandex.ru 
 wrote:

Lennart Augustsson wrote:

And what is a number?
Can't say. You know, it's kinda funny to ask a biologist what it  
means to be

alive.


Are complex numbers numbers?
Beyond any reasonable doubt. Just like you and me are most  
certainly alive.



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Jacques Carette

Lennart Augustsson wrote:

Everyone agrees that the Haskell numeric hierarchy is flawed, but I've
yet to see a good replacement.
  
That's because the good replacement which is mathematically sound 
would be a real mess to work with -- for exactly the same reason that 
Functor , Applicative and Monad are unrelated classes.  See [1].


In a prototype language I am playing with, my version of Num depends on 
15 'previous' classes, and that's likely to increase, not decrease.


Jacques

[1] http://repetae.net/recent/out/classalias.html

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Lennart Augustsson
Complex numbers are just pairs of numbers, and then the various
operations on them are defined in a specific way.
There may be other ways to define the operations on pairs of numbers
that makes sense too.

You can also view complex numbers as polynomials if you wish.  Or two
element lists of numbers.

My real point is that you shouldn't tell others what they should
regard as numbers and what not.
Being a number is in the eye of the beholder. :)

On Mon, Oct 5, 2009 at 4:55 PM, Miguel Mitrofanov miguelim...@yandex.ru wrote:
 No, they aren't. They are polynomials in one variable i modulo i^2+1.

 Seriously, if you say complex numbers are just pairs of real numbers - you
 have to agree that double numbers (sorry, don't know the exact English
 term), defined by

 (a,b)+(c,d) = (a+c,b+d)
 (a,b)(c,d) = (ac, ad+bc)

 are just pairs of real numbers too. After that, you have two choices: a)
 admit that complex numbers and double numbers are the same - and most
 mathematicians would agree they aren't - or b) admit that the relation be
 the same is not transitive - which is simply bizarre.


 Lennart Augustsson wrote:

 But complex numbers are just pairs of numbers.  So pairs of numbers
 can obviously be numbers then.

 On Mon, Oct 5, 2009 at 4:40 PM, Miguel Mitrofanov miguelim...@yandex.ru
 wrote:

 Lennart Augustsson wrote:

 And what is a number?

 Can't say. You know, it's kinda funny to ask a biologist what it means to
 be
 alive.

 Are complex numbers numbers?

 Beyond any reasonable doubt. Just like you and me are most certainly
 alive.

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Finally tagless - stuck with implementation of lam

2009-10-05 Thread Günther Schmidt

Hi all,

I'm playing around with finally tagless.

Here is the class for my Syntax:


class HOAS repr where
lam :: (repr a - repr b) - repr (a - b)
app :: repr (a - b) - repr a - repr b
fix :: (repr a - repr a) - repr a
let_ :: repr a - (repr a - repr b) - repr b

int :: Int - repr Int
add :: repr Int - repr Int - repr Int
sub :: repr Int - repr Int - repr Int
mul :: repr Int - repr Int - repr Int


and here is one instance of that class for semantics.



newtype I a = I { unI :: IO a }

instance HOAS I where
app e1 e2 = I (do
e1' - unI e1
e2' - unI e2
return $ e1' e2')
int i = I (putStrLn (setting an integer:  ++ show i)  return i)
add e1 e2 = I (do
e1' - unI e1
e2' - unI e2
putStrLn (printf adding %d with %d e1' e2')
return $ e1' + e2')
sub e1 e2 = I (do
e1' - unI e1
e2' - unI e2
putStrLn (printf subtracting %d from %d e1' e2')
return $ e1' - e2')
mul e1 e2 = I (do
e1' - unI e1
e2' - unI e2
putStrLn (printf multiplying %d with %d e1' e2')
return $ e1' * e2')


I'm stuck with the lam method, for 2 days now I've been trying to get it  
right, but failed.


Is there a possibility that it isn't even possible?

Günther

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-05 Thread jerzy . karczmarczuk

L.A. says:

complex numbers are just pairs of numbers.

Later :
Being a number is in the eye of the beholder. :) 


Now, the readers of this forum will with horror witness a
discussion about the meaning of the word just...
American people will call it a discussion about semantics, and
we, European will not understand why this word is used in a pejorative
context... 


Just pairs have no natural arithmetic upon them. All the standard set
theory will not help in making numbers, unless we inject the notion of
equivalence à la Gottlob Frege. And this is surely contextual, but perhaps
the eye of the beholder should be somehow objectivized... 

BTW. the missing term of M.M. is DUAL NUMBERS. 

Lennart continues : 

Everyone agrees that the Haskell numeric hierarchy is flawed, 
but I've yet to see a good replacement.


There *are* some mathematical preludes for Haskell. There were attempts
to emulate the structures of, say, the C.A.S. Magma in FP (I lost the
references...) 

http://www.haskell.org/haskellwiki/Mathematical_prelude_discussion 


The problem is, that Haskell is a huge factory, people responsible NOW
for its evolution have other priorities. But the story has at least 15 
years. Jeroen Fokker did something then, I worked on it at the same

period. Now Jacques Carette has his own system, and Sergey Mechveliani
another one...
But other people don't care, so the efforts are atomized. 

Please, keep cool. 


Jerzy Karczmarczuk
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Finally tagless - stuck with implementation of lam

2009-10-05 Thread Jacques Carette
It's possible, but it's not nice.  You need to be able to get out of 
the monad to make the types match, i.e.

   lam f = I (return $ \x - let y = I (return x) in
 unsafePerformIO $ unI (f y))

The use of IO 'forces' lam to transform its effectful input into an even 
more effectful result.  Actually, same goes for any monad used inside a 
'repr'.


let_ and fix follow a similar pattern (although you can hide that 
somewhat by re-using lam if you wish).


Jacques

Günther Schmidt wrote:

Hi all,

I'm playing around with finally tagless.

Here is the class for my Syntax:


class HOAS repr where
lam :: (repr a - repr b) - repr (a - b)
app :: repr (a - b) - repr a - repr b
fix :: (repr a - repr a) - repr a
let_ :: repr a - (repr a - repr b) - repr b

int :: Int - repr Int
add :: repr Int - repr Int - repr Int
sub :: repr Int - repr Int - repr Int
mul :: repr Int - repr Int - repr Int


and here is one instance of that class for semantics.



newtype I a = I { unI :: IO a }

instance HOAS I where
app e1 e2 = I (do
e1' - unI e1
e2' - unI e2
return $ e1' e2')
int i = I (putStrLn (setting an integer:  ++ show i)  return i)
add e1 e2 = I (do
e1' - unI e1
e2' - unI e2
putStrLn (printf adding %d with %d e1' e2')
return $ e1' + e2')
sub e1 e2 = I (do
e1' - unI e1
e2' - unI e2
putStrLn (printf subtracting %d from %d e1' e2')
return $ e1' - e2')
mul e1 e2 = I (do
e1' - unI e1
e2' - unI e2
putStrLn (printf multiplying %d with %d e1' e2')
return $ e1' * e2')


I'm stuck with the lam method, for 2 days now I've been trying to 
get it right, but failed.


Is there a possibility that it isn't even possible?

Günther

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-05 Thread Anton van Straaten

jerzy.karczmarc...@info.unicaen.fr wrote:

American people will call it a discussion about semantics, and
we, European will not understand why this word is used in a pejorative
context...


Semantics *should* be a pejorative word unless it refers to something 
formally specified, and preferably executable or machine-checkable. 
Those subtle Contintental critics of informal semantics, namely Derrida, 
Irigaray, et al, showed us why.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Miguel Mitrofanov


On 5 Oct 2009, at 19:17, Lennart Augustsson wrote:


Complex numbers are just pairs of numbers,


What about dual numbers? (Yes, I've remembered the term) Aren't they  
also just pairs of numbers?



There may be other ways to define the operations on pairs of numbers
that makes sense too.


But these aren't the ways to define pairs of numbers, right?


My real point is that you shouldn't tell others what they should
regard as numbers and what not.


Suppose somebody asks why his Haskell program doesn't work, and after  
some interrogation he
reveals that he just renamed Program.hs to Program.exe. Shouldn't we  
tell him NOT to do this?



Being a number is in the eye of the beholder. :)


Yes, and some points of view aren't as good as other. That's why we  
have psychiatric hospitals.




On Mon, Oct 5, 2009 at 4:55 PM, Miguel Mitrofanov miguelim...@yandex.ru 
 wrote:
No, they aren't. They are polynomials in one variable i modulo  
i^2+1.


Seriously, if you say complex numbers are just pairs of real  
numbers - you
have to agree that double numbers (sorry, don't know the exact  
English

term), defined by

(a,b)+(c,d) = (a+c,b+d)
(a,b)(c,d) = (ac, ad+bc)

are just pairs of real numbers too. After that, you have two  
choices: a)

admit that complex numbers and double numbers are the same - and most
mathematicians would agree they aren't - or b) admit that the  
relation be

the same is not transitive - which is simply bizarre.


Lennart Augustsson wrote:


But complex numbers are just pairs of numbers.  So pairs of numbers
can obviously be numbers then.

On Mon, Oct 5, 2009 at 4:40 PM, Miguel Mitrofanov miguelim...@yandex.ru 


wrote:


Lennart Augustsson wrote:


And what is a number?


Can't say. You know, it's kinda funny to ask a biologist what it  
means to

be
alive.


Are complex numbers numbers?


Beyond any reasonable doubt. Just like you and me are most  
certainly

alive.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-05 Thread Miguel Mitrofanov

Just pairs have no natural arithmetic upon them.


Exactly my point.


BTW. the missing term of M.M. is DUAL NUMBERS.


Remembered this already. Thanks anyway.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-05 Thread Lennart Augustsson
OK, just pairs have no arithmetic, but one way of defining
arithmetic is to treat the pairs as complex numbers.  Or as mantissa
and exponent.  Or as something else.  So there's nothing wrong, IMO,
to make pairs an instance of Num if you so desire.  (Though I'd
probably introduce a new type.)

On Mon, Oct 5, 2009 at 6:46 PM, Miguel Mitrofanov miguelim...@yandex.ru wrote:
 Just pairs have no natural arithmetic upon them.

 Exactly my point.

 BTW. the missing term of M.M. is DUAL NUMBERS.

 Remembered this already. Thanks anyway.

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-05 Thread Miguel Mitrofanov

And I agree that sometimes it can be suitable.

But simply defining an instance of Num without a single word on the  
problem one
is trying to solve is not just pointless. It's something that should  
not be done.


On 5 Oct 2009, at 21:06, Lennart Augustsson wrote:


OK, just pairs have no arithmetic, but one way of defining
arithmetic is to treat the pairs as complex numbers.  Or as mantissa
and exponent.  Or as something else.  So there's nothing wrong, IMO,
to make pairs an instance of Num if you so desire.  (Though I'd
probably introduce a new type.)

On Mon, Oct 5, 2009 at 6:46 PM, Miguel Mitrofanov miguelim...@yandex.ru 
 wrote:

Just pairs have no natural arithmetic upon them.


Exactly my point.


BTW. the missing term of M.M. is DUAL NUMBERS.


Remembered this already. Thanks anyway.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is a number. (Was: Num instances for 2-dimensional types)

2009-10-05 Thread Sönke Hahn
 
 On 5 Oct 2009, at 21:06, Lennart Augustsson wrote:
  OK, just pairs have no arithmetic, but one way of defining
  arithmetic is to treat the pairs as complex numbers.  Or as mantissa
  and exponent.  Or as something else.  So there's nothing wrong, IMO,
  to make pairs an instance of Num if you so desire.  (Though I'd
  probably introduce a new type.)

I was looking for one intuitive way of instantiating pairs of numbers as Num. 
One where i wouldn't have to look in the documentation to remember what (+) 
does. So considering all these examples of what pairs of numbers could be, i 
agree with Miguel Mitrofanov: It's something that should not be done.

Two questions remain, i think:

1. How can i have some notion of addition and subtraction for something that i 
don't want to put in the Num class?

That's easy: I could just write a class that defines binary operators (like 
(+~) and (-~), for example). I don't get  the fanciness of (+), but that's 
okay.

2. How can i use numeric literals to construct values, whose types are not in 
the Num class?

Haskell could provide a class IsNumber (like IsString for string literals). Is 
that something we would want?

BTW, interesting discussion, thanks!

Sönke


On Monday 05 October 2009 07:24:37 pm Miguel Mitrofanov wrote:
 And I agree that sometimes it can be suitable.
 
 But simply defining an instance of Num without a single word on the
 problem one
 is trying to solve is not just pointless. It's something that should
 not be done.
 
  On Mon, Oct 5, 2009 at 6:46 PM, Miguel Mitrofanov miguelim...@yandex.ru
 
   wrote:
  
  Just pairs have no natural arithmetic upon them.
 
  Exactly my point.
 
  BTW. the missing term of M.M. is DUAL NUMBERS.
 
  Remembered this already. Thanks anyway.
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] suggestions for doing date/time values with Data.Generics ?

2009-10-05 Thread Thomas Hartman
I want to patch the time package, which I darcs got head on. Goal is
to be able to do newtype deriving for UTCTime which I reckon is the
base time value, for use in happstack applications state.


basically, need instances for UTCTime, for Data and Typeable.

**
on #haskell:

patch-tag I just darcs got time package and attempted to install.
cabal
   install didn't work because missing configure fle. there's
a .ac
   file there, so I tried first autoconf, then cabal
   install. configure file got created, but failed with
   config.status: error: cannot find input file:
   include/HsTimeConfig.h.in. now what?
patch-tag my goal is to patch time package so can do data generics deriving.

Berengal patch-tag, use System.Time instead?
* Berengal shrugs and sighs [12:20]
patch-tag could try that...
*** o-regalia (n=o-reg...@host-0-130.mimpvbg.clients.pavlovmedia.com)
has
   quit: Lost terminal
Berengal It already has a Serializeable instance defined in one of
the
  happstack modules, so there's probably a Typeable and Data
instance
  somewhere as well



Berengal patch-tag, unfortunately, UTCTime has a component of a
hidden
  datatype which isn't an instance of Typeable or Data, and
since
  it's not exported it's impossible to create the instance as well
Berengal If it were exported, it'd be pretty easy
patch-tag hw can I use UTCTime, deriving Typeable and Data? (want to
use
   UTCTime in happstack).
patch-tag http://moonpatio.com/fastcgi/hpaste.fcgi/view?id=4278#a4278
patch-tag I guess I should have said I'd like to use newtype
deriving rather
   than define instance myself if that's possible.


Berengal patch-tag, that's possible, but could break other things.
The
  correct solution is to patch the existing package, but that
takes
  time
Berengal patch-tag, Day, or something. Can't remember off the top of my head
*** paolino (n=paol...@87.7.161.162) has quit: Leaving.
ski Philonous : if you can't implement both operations (satisfying
laws),
 though, it is probably better to make a new class [12:09]
patch-tag Berengal: a package is hidden if when you do :info in
ghci, it
   comes out as fully qualified, right?
patch-tag pity also that newtype deriving doesn't give you a nicer
error
   message like deriving choked at type blah
Berengal patch-tag, it comes fully qualified if it's not imported,
so you'll
  have to try to import it to see if it's really hidden[12:10]


*

Seems like the right thing to do is patch the time package anyway.


File Edit Options Buffers Tools Haskell Help
{-# LANGUAGE DeriveDataTypeable #-}
module TypeableTime where

import Data.Time
import Data.Data
import Data.Generics
import Data.Typeable

-- doesn't work
--data MyUTCTime = MyUTCTime UTCTime
--   deriving (Typeable,Data)

-- should I work up to UTCTime by doing this...?
data MyDay = MyDay {toMyDayModifiedJulianDay :: Integer}
 deriving (Typeable,Data)

newtype MyString = MyString String
 deriving (Read,Show,Ord,Eq,Typeable,Data)

-- should I just modify time package? is this easier?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: suggestions for doing date/time values with Data.Generics ?

2009-10-05 Thread Thomas Hartman
fwiw, this s what I'm doing till I figure out a better way:

import System.Time
data MyTime = MyTime Integer Integer
  deriving (Typeable,Data)
myTimeToClockTime (MyTime a b) = TOD a b
myTimeFromClockTime (TOD a b) = MyTime a b

and use MyTime in the happstack state.

2009/10/5 Thomas Hartman tphya...@gmail.com:
 I want to patch the time package, which I darcs got head on. Goal is
 to be able to do newtype deriving for UTCTime which I reckon is the
 base time value, for use in happstack applications state.


 basically, need instances for UTCTime, for Data and Typeable.

 **
 on #haskell:

 patch-tag I just darcs got time package and attempted to install.
 cabal
           install didn't work because missing configure fle. there's
 a .ac
           file there, so I tried first autoconf, then cabal
           install. configure file got created, but failed with
           config.status: error: cannot find input file:
           include/HsTimeConfig.h.in. now what?
 patch-tag my goal is to patch time package so can do data generics deriving.

 Berengal patch-tag, use System.Time instead?
 * Berengal shrugs and sighs                                             
 [12:20]
 patch-tag could try that...
 *** o-regalia (n=o-reg...@host-0-130.mimpvbg.clients.pavlovmedia.com)
 has
   quit: Lost terminal
 Berengal It already has a Serializeable instance defined in one of
 the
          happstack modules, so there's probably a Typeable and Data
 instance
          somewhere as well



 Berengal patch-tag, unfortunately, UTCTime has a component of a
 hidden
          datatype which isn't an instance of Typeable or Data, and
 since
          it's not exported it's impossible to create the instance as well
 Berengal If it were exported, it'd be pretty easy
 patch-tag hw can I use UTCTime, deriving Typeable and Data? (want to
 use
           UTCTime in happstack).
 patch-tag http://moonpatio.com/fastcgi/hpaste.fcgi/view?id=4278#a4278
 patch-tag I guess I should have said I'd like to use newtype
 deriving rather
           than define instance myself if that's possible.


 Berengal patch-tag, that's possible, but could break other things.
 The
          correct solution is to patch the existing package, but that
 takes
          time
 Berengal patch-tag, Day, or something. Can't remember off the top of my head
 *** paolino (n=paol...@87.7.161.162) has quit: Leaving.
 ski Philonous : if you can't implement both operations (satisfying
 laws),
     though, it is probably better to make a new class                 [12:09]
 patch-tag Berengal: a package is hidden if when you do :info in
 ghci, it
           comes out as fully qualified, right?
 patch-tag pity also that newtype deriving doesn't give you a nicer
 error
           message like deriving choked at type blah
 Berengal patch-tag, it comes fully qualified if it's not imported,
 so you'll
          have to try to import it to see if it's really hidden        [12:10]


 *

 Seems like the right thing to do is patch the time package anyway.


 File Edit Options Buffers Tools Haskell Help
 {-# LANGUAGE DeriveDataTypeable #-}
 module TypeableTime where

 import Data.Time
 import Data.Data
 import Data.Generics
 import Data.Typeable

 -- doesn't work
 --data MyUTCTime = MyUTCTime UTCTime
 --   deriving (Typeable,Data)

 -- should I work up to UTCTime by doing this...?
 data MyDay = MyDay {toMyDayModifiedJulianDay :: Integer}
  deriving (Typeable,Data)

 newtype MyString = MyString String
  deriving (Read,Show,Ord,Eq,Typeable,Data)

 -- should I just modify time package? is this easier?

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell Platform - changing the global install dir

2009-10-05 Thread Paul Moore
I've installed the Haskell Platform to a non-default location
(D:\Apps\Haskell) to avoid some of the Win7 funniness over writing to
C:\Program Files. However, even though I've done this, the cabal
global install directory is still C:\Program Files\haskell. This has
been added to my PATH and is used by default.

Is there a way I could have specified that I want the global install
directory in D:\Apps\Haskell? I guess I could hack my cabal\config
file (and presumably change PATH) but that seems a bit ugly. Is the
use of Program Files even when the install was to somewhere else a
bug?

It's not a big deal - I can easily stick to user installs for now.

Thanks,
Paul.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Henning Thielemann
Sönke Hahn schrieb:
 Hi!
 
 I often stumble upon 2- (or 3-) dimensional numerical data types like
 
 (Double, Double)
 
 or similar self defined ones. I like the idea of creating instances for Num 
 for 
 these types. The meaning of (+), (-) and negate is clear and very intuitive, 
 i 
 think. I don't feel sure about (*), abs, signum and fromInteger. I used to 
 implement
 
 fromInteger n = (r, r) where r = fromInteger n
 
 , but thinking about it, 
 
 fromInteger n = (fromInteger n, 0)
 
 seems very reasonable, too. 
 
 Any thoughts on that? How would you do it?

I use NumericPrelude that has more fine grained type classes. E.g. (+)
is in Additive and (*) is in Ring.

http://hackage.haskell.org/package/numeric-prelude


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] System.Random.Mersenne - no randomR variants

2009-10-05 Thread Paul Moore
I notice that System.Random.Mersenne has no randomR variants. Is there
a reason for this, or is it just an oversight? It makes porting code
from System.Random a little more complicated than it needs to be. I
know it's possible to write a function mapping a Double (or other
value, as appropriate) to a range, effectively replacing randomR, but
it's fiddly to get the edge cases right. A standard implementation
would be helpful.

Paul
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] System.Random.Mersenne - no randomR variants

2009-10-05 Thread Don Stewart
p.f.moore:
 I notice that System.Random.Mersenne has no randomR variants. Is there
 a reason for this, or is it just an oversight? It makes porting code
 from System.Random a little more complicated than it needs to be. I
 know it's possible to write a function mapping a Double (or other
 value, as appropriate) to a range, effectively replacing randomR, but
 it's fiddly to get the edge cases right. A standard implementation
 would be helpful.

Basically, to use the type class interface defined in System.Random, you
will suffer a 100x decrease in performance, as  the instances all
convert via Integer. 

Rather than give people a surprise, I chose not to implement that
interface.

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] System.Random.Mersenne - no randomR variants

2009-10-05 Thread Paul Moore
2009/10/5 Don Stewart d...@galois.com:
 p.f.moore:
 I notice that System.Random.Mersenne has no randomR variants. Is there
 a reason for this, or is it just an oversight? It makes porting code
 from System.Random a little more complicated than it needs to be. I
 know it's possible to write a function mapping a Double (or other
 value, as appropriate) to a range, effectively replacing randomR, but
 it's fiddly to get the edge cases right. A standard implementation
 would be helpful.

 Basically, to use the type class interface defined in System.Random, you
 will suffer a 100x decrease in performance, as  the instances all
 convert via Integer.

 Rather than give people a surprise, I chose not to implement that
 interface.

Sounds fair enough :-)

Excuse my ignorance, but although System.Random uses Integer, why
can't your implementation work with Int and other fast types? Is this
something to do with how classes work?

Also, a minor documentation question - the documentation for
getStdRandom seems confused (or I am!):

getStdRandom :: (MTGen - IO a) - IO a Source

Uses the supplied function to get a value from the current global
random generator, and updates the global generator with the new
generator returned by the function. For example, rollDice gets a
random integer between 1 and 6:

  rollDice :: IO Int
  rollDice = getMTRandom (randomR (1,6))

Is this right? It seems to imply there is a way to use randomR. If I
did, would performance be impacted as you mention above?

Thanks, and sorry for the dumb questions.

Paul.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Designing a DSL?

2009-10-05 Thread Günther Schmidt

Hello Doaitse,

thank you very much!

Best regards

Günther
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Finally tagless - stuck with implementation of lam

2009-10-05 Thread Günther Schmidt

Hello Jacques,

thanks, that is disappointing in some way, guess I still have a lot to  
learn.


Günther


Am 05.10.2009, 18:06 Uhr, schrieb Jacques Carette care...@mcmaster.ca:

It's possible, but it's not nice.  You need to be able to get out of  
the monad to make the types match, i.e.

lam f = I (return $ \x - let y = I (return x) in
  unsafePerformIO $ unI (f y))

The use of IO 'forces' lam to transform its effectful input into an even  
more effectful result.  Actually, same goes for any monad used inside a  
'repr'.


let_ and fix follow a similar pattern (although you can hide that  
somewhat by re-using lam if you wish).


Jacques

Günther Schmidt wrote:

Hi all,

I'm playing around with finally tagless.

Here is the class for my Syntax:


class HOAS repr where
lam :: (repr a - repr b) - repr (a - b)
app :: repr (a - b) - repr a - repr b
fix :: (repr a - repr a) - repr a
let_ :: repr a - (repr a - repr b) - repr b

int :: Int - repr Int
add :: repr Int - repr Int - repr Int
sub :: repr Int - repr Int - repr Int
mul :: repr Int - repr Int - repr Int


and here is one instance of that class for semantics.



newtype I a = I { unI :: IO a }

instance HOAS I where
app e1 e2 = I (do
e1' - unI e1
e2' - unI e2
return $ e1' e2')
int i = I (putStrLn (setting an integer:  ++ show i)  return i)
add e1 e2 = I (do
e1' - unI e1
e2' - unI e2
putStrLn (printf adding %d with %d e1' e2')
return $ e1' + e2')
sub e1 e2 = I (do
e1' - unI e1
e2' - unI e2
putStrLn (printf subtracting %d from %d e1' e2')
return $ e1' - e2')
mul e1 e2 = I (do
e1' - unI e1
e2' - unI e2
putStrLn (printf multiplying %d with %d e1' e2')
return $ e1' * e2')


I'm stuck with the lam method, for 2 days now I've been trying to get  
it right, but failed.


Is there a possibility that it isn't even possible?

Günther

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe




___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] dsl and gui toolkit

2009-10-05 Thread Chris Eidhof
That sounds really interesting, it would be great if you could share  
some of your work by putting it on hackage or posting a link to the  
repository!


-chris

On 5 okt 2009, at 12:42, Andrew U. Frank wrote:

writing a gui is a mess (independent of wx or gtk) - too much detail  
is shown

and not enough abstraction is done. haskell can help.

i have written an experimental way of producing the GUI   
automatically with a
description of the semantics of the types and operations involved (a  
la

ontology, evnetually comparable what protege produces).
the input is a descriptionof the entity ypes, the fields used, the  
functional

dependencies between the fiels, plus the operations used.
the division in screens and their layout.

the rest ist automatic.
the result is a GUI (with preferably gtk but i had also a wx version  
running).


the ideas were inspired by eliot conal's work and wxgeneric, which  
seemed for

administrative applications either too restricted or to specific.

if somebody wants to try it out for his application, please write
fr...@geoinfo.tuwien.ac.at

(there is not much documentation and the code is not yet completely  
clean -

testing by somebody else would be very valuable!)

andrew

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Soenke Hahn
On Monday 05 October 2009 10:14:02 pm Henning Thielemann wrote:
 Sönke Hahn schrieb:
  Hi!
 
  I often stumble upon 2- (or 3-) dimensional numerical data types like
 
  (Double, Double)
 
  or similar self defined ones. I like the idea of creating instances for
  Num for these types. The meaning of (+), (-) and negate is clear and very
  intuitive, i think. I don't feel sure about (*), abs, signum and
  fromInteger. I used to implement
 
  fromInteger n = (r, r) where r = fromInteger n
 
  , but thinking about it,
 
  fromInteger n = (fromInteger n, 0)
 
  seems very reasonable, too.
 
  Any thoughts on that? How would you do it?
 
 I use NumericPrelude that has more fine grained type classes. E.g. (+)
 is in Additive and (*) is in Ring.
 
 http://hackage.haskell.org/package/numeric-prelude
 

That is pretty cool, thanks. How do your import statements look like, when you 
use numeric-prelude? Mine look a bit ugly:

import Prelude hiding ((+), (-), negate)
import Algebra.Additive ((+), (-), negate)

Sönke

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Finally tagless - stuck with implementation of lam

2009-10-05 Thread Jacques Carette

BTW, here is a more symmetric version of the same code:
   lam f = I . return $ unsafePerformIO . unI . f . I . return

which has a very clear pattern of
 lam f = embed $ extract . f. embed

where 'embed' is often called return.  Implementations of lam in 
tagless final style tend to follow the above pattern of embed/extract, 
each specialized to the particular repr implementation. 

In some cases, one only needs a context-sensitive extract, i.e. an 
extract which is only valid in the context of an outer 'embed'.  The 
most important example is code-generation in metaocaml where the 
'compiler' version of lam reads

 let lam f = .fun x - .~(f .x.).
where the .~ does an extract -- but *only* in the context of a 
surrounding code bracket (i.e. . . ). 

If there is such a context-sensitive extract for the IO monad, i.e. 
something which allows you to pretend you've got a result in IO only 
valid *inside* IO, then you can use that to write a nicer lam. 

I tried all the obvious things with monadic operators to get this done, 
but did not succeed in the time I had.  Maybe Oleg or Ken can.  So don't 
give up hope quite yet!


Jacques

Günther Schmidt wrote:

Hello Jacques,

thanks, that is disappointing in some way, guess I still have a lot to 
learn.


Günther


Am 05.10.2009, 18:06 Uhr, schrieb Jacques Carette care...@mcmaster.ca:

It's possible, but it's not nice.  You need to be able to get out of 
the monad to make the types match, i.e.

lam f = I (return $ \x - let y = I (return x) in
  unsafePerformIO $ unI (f y))

The use of IO 'forces' lam to transform its effectful input into an 
even more effectful result.  Actually, same goes for any monad used 
inside a 'repr'.


let_ and fix follow a similar pattern (although you can hide that 
somewhat by re-using lam if you wish).


Jacques


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] I/O Haskell question

2009-10-05 Thread Terry Hayes
I found the handling of (IO t) by the interpreter (GHCI in my case) to be 
somewhat confusing.  As pointed out below, I can type:

readFile bla  ::  IO String

and GHCI happily displays the contents of the file.  However neither of the 
following work

print $ readFile bla
putStr $ readFile bla

In other words, GHCI seems perfectly willing to unwrap a type (IO t) and 
display it (assuming Show t).  This bit of helpfulness may just confuse us 
novice users by allowing us to stray from the correct way to deal with wrapped 
types (monads).

content - readFile bla
print content
putStr content

Terry





From: Maria Boghiu maria.bog...@gmail.com
To: haskell-cafe@haskell.org
Sent: Monday, October 5, 2009 6:48:56 AM
Subject: [Haskell-cafe] I/O Haskell question

Hey.

I'm trying to configure Xmonad, the window manager.

for this purpose, I'm trying to read the workspaces variable in the code below 
from file.
As you can see, I do workspaces = readWS where

readWS = do
 l - readFile ~/bla
 return l

I get an error saying I am mismatching types IO [String] and [String].
But I thought that once one does l - readFile ~/bla, l is the a string or, 
in this case, a String list. If I run that line in prelude it seems to be 
working fine, prints the content of the file ~/bla on screen (though I'm not 
sure if as a String or as a list of Strings, i.e. [String])___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Finally tagless - stuck with implementation of lam

2009-10-05 Thread Robert Atkey
Hi Günther,

The underlying problem with the implementation of 'lam' is that 
you have to pick an evaluation order for the side effects you want in
the semantics of your embedded language. The two obvious options are
call-by-name and call-by-value.

The tricky point is that the types of the embedded language cannot be
interpreted directly as Haskell types wrapped in a monad. You need to 
either take the call-by-name or the call-by-value interpretation of
types:

For CBN:  [[ Int]] = IO Int
  [[ A - B ]] = [[ A ]] - [[ B ]]

For CBV:  [[ Int]] = Int
  [[ A - B ]] = [[ A ]] - IO [[ B ]]

(obviously, there is nothing special about the IO monad here, or in the
rest of this email: we could replace it with any other monad).

To implement the translation of embedded language types to Haskell types
in Haskell we use type families.

Here is the code for call-by-name:

 module CBN where

First of all, we define some dummy types so that we have a different
representation of types in the embedded language than those in the
meta-language, and we don't get confused:

 data IntT
 data a :- b
 infixr 5 :-

Now we give the definition of the higher-order abstract syntax of our
embedded language:

 class HOAS exp where
 lam :: (exp a - exp b) - exp (a :- b)
 app :: exp (a :- b) - exp a - exp b

 int :: Int - exp IntT
 add :: exp IntT - exp IntT - exp IntT

This is as in your definition, except I have used the different type
names to highlight the distinction between embedded and meta-language
types.

Next, we give the CBN semantics for the types, using the definition
above, with a type family.

 type family Sem a :: *
 type instance Sem IntT  = IO Int
 type instance Sem (a :- b) = Sem a - Sem b

Now we can give an instance of the syntax's type class, that translates
a piece of embedded code into its denotational semantics.

 newtype S a = S { unS :: Sem a }

 instance HOAS S where
   int = S . return
   add (S x) (S y) = S $ do a - x
b - y
putStrLn Adding
return (a + b)

   lam f   = S (unS . f . S)
   app (S x) (S y) = S (x y)

As an example, we can give a term and see what happens when we evaluate
it:

 let_ :: HOAS exp = exp a - (exp a - exp b) - exp b
 let_ x y = (lam y) `app` x

 t :: HOAS exp = exp IntT
 t = (lam $ \x - let_ (x `add` x)
  $ \y - y `add` y) `app` int 10

Evaluating 'unS t' in GHCi gives the output:

Adding
Adding
Adding
40

Note that the add operation is invoked three times: the x `add` x that
is let-bound is evaluated twice.



The second option is call-by-value. This is a bit more interesting
because we have to change the syntax of the embedded language to deal
with the different substitution rules for CBV.

 module CBV where

Again, we use a different representation for embedded-language types:

 data IntT
 data a :- b
 infixr 5 :-

There is a difference in the syntax between CBN and CBV that is not
always obvious from the usual paper presentations. There is a split
between pieces of syntax that are values and those that are
computations. Values do not have side-effects, while computations may.
In this presentation, I have chosen that the only values are variables,
while everything else is a computation.

To represent this split, we use a multi-parameter type class. Note that
the technique of using multi-parameter type classes is generally useful
for representing abstract syntaxes in the HOAS style with multiple
mutually defined syntactic categories.

 class HOAS exp val | exp - val, val - exp where
val :: val a - exp a

lam :: (val a - exp b) - exp (a :- b)
app :: exp (a :- b) - exp a - exp b

int :: Int - exp IntT
add :: exp IntT - exp IntT - exp IntT

The 'val' operation injects values into computations: this will be
interpreted by the 'return' of the monad.

We now give the semantics of types for CBV, following the definition
above:

 type family   Sem a :: *
 type instance Sem IntT  = Int
 type instance Sem (a :- b) = Sem a - IO (Sem b)

We need two newtypes for the two different syntactic categories. Values
are interpeted by 'SV', and are just pure values; computations are
interpreted by wrapping them in the monad.

 newtype SV a = SV { unSV :: Sem a }
 newtype SC a = SC { unSC :: IO (Sem a) }

Now we can define the semantics of the syntax in terms of these types:

 instance HOAS SC SV where
 val = SC . return . unSV

 lam f = SC $ return (unSC . f . SV) 
 app (SC x) (SC y) = SC $ do f - x; a - y; f a
 
 int i = SC $ return i
 add (SC x) (SC y) = SC $ do a - x
 b - y
 putStrLn Adding
 return (a + b)

The same example term is expressed in CBV as follows:

 let_ :: HOAS exp val = exp a - (val a - exp b) - exp b
 let_ x y = (lam y) `app` x

 t :: HOAS exp val = exp IntT
 t = 

Re: [Haskell-cafe] Mutable data within a (non-IO) monad

2009-10-05 Thread Bryan O'Sullivan
On Sat, Oct 3, 2009 at 1:57 AM, Duncan Coutts
duncan.cou...@googlemail.comwrote:


 Internally, each time you demand the next random number, it is mutating
 the internal ST array.


This is the same thing that the Statistics.RandomVariate code in the
statistics package does, and it can be very fast:
http://www.serpentine.com/blog/2009/09/19/a-new-pseudo-random-number-generator-for-haskell/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Henning Thielemann


On Mon, 5 Oct 2009, Soenke Hahn wrote:


On Monday 05 October 2009 10:14:02 pm Henning Thielemann wrote:


I use NumericPrelude that has more fine grained type classes. E.g. (+)
is in Additive and (*) is in Ring.

http://hackage.haskell.org/package/numeric-prelude



That is pretty cool, thanks. How do your import statements look like, when you
use numeric-prelude? Mine look a bit ugly:

import Prelude hiding ((+), (-), negate)
import Algebra.Additive ((+), (-), negate)


{-# LANGUAGE NoImplicitPrelude #-}

or

import Prelude ()

and

import qualified Algebra.Additive as Additive   (e.g. for Additive.C)
import NumericPrelude
import PreludeBase

The first form is necessary if you use number literals, what is the case 
for you I think.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Num instances for 2-dimensional types

2009-10-05 Thread Soenke Hahn
On Monday 05 October 2009 11:58:28 pm Henning Thielemann wrote:
 On Mon, 5 Oct 2009, Soenke Hahn wrote:
  On Monday 05 October 2009 10:14:02 pm Henning Thielemann wrote:
  I use NumericPrelude that has more fine grained type classes. E.g. (+)
  is in Additive and (*) is in Ring.
 
  http://hackage.haskell.org/package/numeric-prelude
 
  That is pretty cool, thanks. How do your import statements look like,
  when you use numeric-prelude? Mine look a bit ugly:
 
  import Prelude hiding ((+), (-), negate)
  import Algebra.Additive ((+), (-), negate)
 
 {-# LANGUAGE NoImplicitPrelude #-}
 
 or
 
 import Prelude ()
 
 and
 
 import qualified Algebra.Additive as Additive   (e.g. for Additive.C)
 import NumericPrelude
 import PreludeBase
 
 The first form is necessary if you use number literals, what is the case
 for you I think.
 

Thanks.

If you want to use number literals, you have to implement an instance for 
Algebra.Ring.C, if i understand correctly. Is there any special reason, why 
fromInteger is a method of Algebra.Ring.C?

Sönke
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Finally tagless - stuck with implementation of lam

2009-10-05 Thread David Menendez
2009/10/5 Robert Atkey bob.at...@ed.ac.uk:
 Hi Günther,

 The underlying problem with the implementation of 'lam' is that
 you have to pick an evaluation order for the side effects you want in
 the semantics of your embedded language. The two obvious options are
 call-by-name and call-by-value.

I wonder how easily one can provide both, like in Algol.


 The other obvious evaluation strategy is call-by-need, as used by
 Haskell itself, but I don't know if it is possible to implement this. I
 guess it may be possible using the ST monad as the mutable storage of
 thunks.

Perhaps something along the lines of Purely Functional Lazy
Non-deterministic Programming?

http://okmij.org/ftp/Computation/monads.html#lazy-sharing-nondet

Obviously, doing a deterministic version is simpler. You can probably
get away with representing values as simple self-evaluating thunks.

data Thunk s a = STRef s (Either a (ST s a))

evalThunk :: Thunk s a - ST s a
evalThunk r = readSTRef r = either return update
where
update m = m = \x - writeSTRef r (Left x)  return x

-- 
Dave Menendez d...@zednenem.com
http://www.eyrie.org/~zednenem/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Generalizing IO

2009-10-05 Thread Floptical Logic
The code below is a little interactive program that uses some state.
It uses StateT with IO to keep state.  My question is: what is the
best way to generalize this program to work with any IO-like
monad/medium?  For example, I would like the program to function as it
does now using stdin but I would also like it to function over IRC
using the Net monad from
http://haskell.org/haskellwiki/Roll_your_own_IRC_bot.  Thanks for
any suggestions.

-- begin code --
import Control.Monad
import Control.Monad.State
import Data.List

data PD = PD
{ pdCount :: Int
, pdList  :: [String]
} deriving (Show)

type PDState = StateT PD IO

main = runStateT loop (PD { pdCount = 0, pdList = [] })

loop :: PDState a
loop = forever $ do
cmd - liftIO getLine
runCmd cmd

runCmd :: String - PDState ()
runCmd Inc = increment
runCmd PrintCount = liftIO . print = getCount
runCmd PrintList = liftIO . print = getList
runCmd str | Add  `isPrefixOf` str = addToList $ drop 4 str
runCmd _ = return ()

getCount :: PDState Int
getCount = pdCount `liftM` get

getList :: PDState [String]
getList = pdList `liftM` get

increment :: PDState ()
increment = modify $ \st - st { pdCount = pdCount st + 1 }

addToList :: String - PDState ()
addToList str = modify $ \st - st { pdList = pdList st ++ [str]}
-- end code --
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Generalizing IO

2009-10-05 Thread David Menendez
On Mon, Oct 5, 2009 at 7:56 PM, Floptical Logic flopticalo...@gmail.com wrote:
 The code below is a little interactive program that uses some state.
 It uses StateT with IO to keep state.  My question is: what is the
 best way to generalize this program to work with any IO-like
 monad/medium?  For example, I would like the program to function as it
 does now using stdin but I would also like it to function over IRC
 using the Net monad from
 http://haskell.org/haskellwiki/Roll_your_own_IRC_bot.  Thanks for
 any suggestions.

Instead of specifying the monad implementation, specify the interface.
That is, you are using state operations (from MonadState) and IO
operations (from MonadIO). Try removing all the type signatures that
mention PDState and see what you get.

E.g., loop :: (MonadState PD m, MonadIO m) = m a

-- 
Dave Menendez d...@zednenem.com
http://www.eyrie.org/~zednenem/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Generalizing IO

2009-10-05 Thread Gregory Crosswhite
My thought is that you could simply drop the IO from your type  
definition,


type PDState = StateT PD

You will need to change all of your type signature from PDState  
type to PDState m type to make them all polymorphic over the  
choice of monad.  Then all you should need to do is to generalize the  
loop function to accept a line-fetching monad from the user:


loop :: m a - PDState m a
loop getLine = forever $ do
  cmd - lift getLine
  runCmd cmd

Note how liftIO was changed to lift, which works for any monad and  
comes built-in with the StateT monad.


Hope this helps!

Cheers,
Greg


On Oct 5, 2009, at 4:56 PM, Floptical Logic wrote:


The code below is a little interactive program that uses some state.
It uses StateT with IO to keep state.  My question is: what is the
best way to generalize this program to work with any IO-like
monad/medium?  For example, I would like the program to function as it
does now using stdin but I would also like it to function over IRC
using the Net monad from
http://haskell.org/haskellwiki/Roll_your_own_IRC_bot.  Thanks for
any suggestions.

-- begin code --
import Control.Monad
import Control.Monad.State
import Data.List

data PD = PD
   { pdCount :: Int
   , pdList  :: [String]
   } deriving (Show)

type PDState = StateT PD IO

main = runStateT loop (PD { pdCount = 0, pdList = [] })

loop :: PDState a
loop = forever $ do
   cmd - liftIO getLine
   runCmd cmd

runCmd :: String - PDState ()
runCmd Inc = increment
runCmd PrintCount = liftIO . print = getCount
runCmd PrintList = liftIO . print = getList
runCmd str | Add  `isPrefixOf` str = addToList $ drop 4 str
runCmd _ = return ()

getCount :: PDState Int
getCount = pdCount `liftM` get

getList :: PDState [String]
getList = pdList `liftM` get

increment :: PDState ()
increment = modify $ \st - st { pdCount = pdCount st + 1 }

addToList :: String - PDState ()
addToList str = modify $ \st - st { pdList = pdList st ++ [str]}
-- end code --
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Haskell Platform - changing the global install dir

2009-10-05 Thread Mikhail Glushenkov
Hi Paul,

Paul Moore p.f.moore at gmail.com writes:

 Is there a way I could have specified that I want the global install
 directory in D:\Apps\Haskell? I guess I could hack my cabal\config
 file (and presumably change PATH) but that seems a bit ugly. 

A bit ugly? Why? That's precisely what the config files are for.

 Is the
 use of Program Files even when the install was to somewhere else a
 bug?

Not really, the Windows installer just doesn't tinker with the
default cabal-install install location. There are plans, though,
to implement an install only for the current user mode
for the next release.



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Finally tagless - stuck with implementation of?lam

2009-10-05 Thread Chung-chieh Shan
Robert Atkey bob.at...@ed.ac.uk wrote in article 
1254778973.3675.42.ca...@bismuth in gmane.comp.lang.haskell.cafe:
 To implement the translation of embedded language types to Haskell types
 in Haskell we use type families.

This type-to-type translation is indeed the crux of the trickiness.  By
the way, Section 4.3 of our (JFP) paper describes how to follow such a
translation without type families.  If I were to avoid type families in
Haskell, I would make Symantics into a multiparameter type class

  class HOAS repr arrow int where

lam :: (repr a - repr b) - repr (arrow a b)
app :: repr (arrow a b) - repr a - repr b
fix :: (repr a - repr a) - repr a
let_ :: repr a - (repr a - repr b) - repr b

int :: int - repr int
add :: repr int - repr int - repr int
sub :: repr int - repr int - repr int
mul :: repr int - repr int - repr int

 The underlying problem with the implementation of 'lam' is that 
 you have to pick an evaluation order for the side effects you want in
 the semantics of your embedded language. The two obvious options are
 call-by-name and call-by-value.

(Section 5 of our (JFP) paper addresses both CBN and CBV.)

-- 
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
Here's a souvenir of it. He made me write this down so I'd remember
to get this book and read it. Transcendent Speculations on Apparent
Design in the Fate of the Individual, that's a mouthful isn't it. I
wrote this down at gun-point. - Gaddis

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Market Place for Haskell development teams?

2009-10-05 Thread Jörg Roman Rudnick

Hi Alberto,

you are working on *second order scalibility*?? Great. May I regard you 
a one of the first of a breed of Haskell business evangelists?? ;-))


Somebody stated here - sorry, the name's missing - the relevance of 
Hackage being diminuished by the great amount of *scientific* libraries, 
no joke... Personally, I don't think Haskell should become like Java  
Co. So for at least for two reasons, I see at least two reasons to speak 
open about what you are seemingly interested:


o   to support Haskell library developers to better realize the value of 
their work, and teams intending software projects in the non-standard 
areas to realize advantages of using Haskell, once they are given


o   to prevent conflicts, when Haskell grows economically more 
successful, and allowing a harmonious transition between both cultures


Keep on the work ;-)

   Nick

Alberto G. Corona wrote:





This reminds me of the whole agent thing -- pretty much dominated
by Java (e.g., Jade, Jason, Jack) nowadays --, for which I would
bet lots things are done more straigthforward using Haskell --
especially those parts the Java coders are usually proud of...
Let's maybe speak of *second order scalability*:

As first order scalability would rather be a matter in space time
load increased by repetitions, the concern of second order
scalability would be more about a *fractal* expansion of concepts
like a *closure* -- Haskell, already in a vivid exchange with
interactive theorem proving (e.g. Coq adopts type classes from
Haskell and dependent types vice versa) seems excellently
prepared... :-)


Interesting. I´m working in something like second order scalability. 
Instead of brute performance by  redundancy,  high speed networks and 
fast disks, scalability can be achieved by looking at the properties 
of the data. 



I ever tended to say financial applications are especially prone
to be boring -- the prototype of repetitive IT, even for strategy
the stupid 'traffic lights cockpits' or OLAP(!) ... But this
problem is rather supply driven to me.

For sure. This is supply driven. There are a lack of new ideas mainly 
because the technology is low level and obsolete.
 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Finally tagless - stuck with implementation of?lam

2009-10-05 Thread Don Stewart
ccshan:
   class HOAS repr arrow int where
 
 lam :: (repr a - repr b) - repr (arrow a b)
 app :: repr (arrow a b) - repr a - repr b
 fix :: (repr a - repr a) - repr a
 let_ :: repr a - (repr a - repr b) - repr b
 
 int :: int - repr int
 add :: repr int - repr int - repr int
 sub :: repr int - repr int - repr int
 mul :: repr int - repr int - repr int
 
  The underlying problem with the implementation of 'lam' is that 
  you have to pick an evaluation order for the side effects you want in
  the semantics of your embedded language. The two obvious options are
  call-by-name and call-by-value.
 
 (Section 5 of our (JFP) paper addresses both CBN and CBV.)

Do you have a link to the paper?

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Market Place for Haskell development teams?

2009-10-05 Thread Jörg Roman Rudnick

Hi Curt,


in case you regard as 'mainstream' big industry projects, this is not 
the thing at least I am speaking about. I am speaking about small and 
especially medium sized projects.


Frankly, I think that:

o   there are people among us which at some times have influence on 
decisions about the software platform of projects - which tend to 
hesitate in proposing Haskell, as they do not see an appropriate 
infrastructure at hand.


This not necessarily needs to be the 'classical' enterprise-employee 
thing - the occasion to know a group of experts to be able to engage in 
a looser cooperation might serve well, too, etc., etc.


o   there are, on the other side, people among us, wanting exactly to do 
this...


Why not let them cooperate, no matter how big it will grow in comparison 
to Java  Co, in a way appropriate to the Haskell community?


   Nick
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Market Place for Haskell development teams?

2009-10-05 Thread Jörg Roman Rudnick

Hi Thomas,

two very substantial contributions... :-)

(a) Yes, let's do it with Happstack.

(b) I just applied for the group.

   Nick

Thomas Hartman wrote:

Hey, first of all, in terms of a platform for promoting haskell
commercially, happstutorial.com actually implements a job board.

Yeah, it's primitive and not feature complete, but on hackage, open
source, and ready for anyone who would like to work on it. (Currently
maintained by creighton hogg.)

This was my baby in 2008, when I was looking to foster happs for web
development, as a sort of smarter ruby on rails, which I am using in
the field in patch-tag.com.

2, the haskell-startup google group at

http://groups.google.com/group/haskell-startup

It's private, to encourage slightly more courageous business talk away
from the panoptic gaze of google, but I approve pretty much anyone who
doesn't want in and isn't a bot.

Yes. Let's create a world with more jobs for haskell developers, and
better software for everyone :)

thomas.
  


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Market Place for Haskell development teams?

2009-10-05 Thread Jörg Roman Rudnick

Hi John,


IMHO, with medium sized projects which are not application software to 
be installed on a greater number of unknown systems, the problem 
described by you is less aggravating:


Hackage offers a fairly good track of version history and I for myself 
have adapted versions a good deal of times and found it - easy, to be 
honest.


Speaking about small and especially medium sized projects, I think agile 
development fits well this scope. Please do not forget this.


Nick

John A. De Goes wrote:

On Oct 1, 2009, at 12:13 AM, Curt Sampson wrote:


And as far as something like dealing with a changing language and
libraries, the mainstream already has well-established and popular
techniques for doing just: agile development.


A project manager's worst nightmare:

Sorry boss, but we're just not going to be able to meet that 
deadline, because, well, a language extension we were using was 
dropped from the language, and the syntax for some core operators was 
changed. Not only is our code broken, but many of the libraries we 
were using are broken. Don't worry, though, we're 'agile', so our unit 
tests will tell us when our code is working again.


Big business demands stability.

Regards,

John


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Generalizing IO

2009-10-05 Thread Floptical Logic
 Instead of specifying the monad implementation, specify the interface.
 That is, you are using state operations (from MonadState) and IO
 operations (from MonadIO). Try removing all the type signatures that
 mention PDState and see what you get.

 E.g., loop :: (MonadState PD m, MonadIO m) = m a

If I were to make an instance of MonadIO be a parameter to StateT and
I wanted to use the Net monad (from Roll your own IRC bot on the wiki)
with it, I would need to make Net an instance of MonadIO.  What would
this instance look like?

I think the loop function is the least of my worries.  I am more
concerned about the runCmd function.  What would go in place of print
in runCmd?

Thanks
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Generalizing IO

2009-10-05 Thread Antoine Latter
On Mon, Oct 5, 2009 at 10:54 PM, Floptical Logic
flopticalo...@gmail.com wrote:

 If I were to make an instance of MonadIO be a parameter to StateT and
 I wanted to use the Net monad (from Roll your own IRC bot on the wiki)
 with it, I would need to make Net an instance of MonadIO.  What would
 this instance look like?

If you define 'Net' as in the tutorial above, it will already be an
instance of MonadIO :-)

 I think the loop function is the least of my worries.  I am more
 concerned about the runCmd function.  What would go in place of print
 in runCmd?

The function 'liftIO . print' will work in any monad which is an
instance of MonadIO. Take a look at
http://hackage.haskell.org/packages/archive/mtl/1.1.0.2/doc/html/Control-Monad-Trans.html#v:liftIO
for where 'liftIO' comes from.

Antoine
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Generalizing IO

2009-10-05 Thread David Menendez
On Mon, Oct 5, 2009 at 11:54 PM, Floptical Logic
flopticalo...@gmail.com wrote:
 Instead of specifying the monad implementation, specify the interface.
 That is, you are using state operations (from MonadState) and IO
 operations (from MonadIO). Try removing all the type signatures that
 mention PDState and see what you get.

 E.g., loop :: (MonadState PD m, MonadIO m) = m a

 If I were to make an instance of MonadIO be a parameter to StateT and
 I wanted to use the Net monad (from Roll your own IRC bot on the wiki)
 with it, I would need to make Net an instance of MonadIO.  What would
 this instance look like?

You're referring to this type?

type Net = ReaderT Bot IO

That already is an instance of MonadIO. The relevant instances are

instance MonadIO IO where
liftIO = id

instance MonadIO m = MonadIO (ReaderT r m) where
liftIO = lift . liftIO


 I think the loop function is the least of my worries.  I am more
 concerned about the runCmd function.  What would go in place of print
 in runCmd?

You're already using liftIO from MonadIO in the definition of runCmd,
so no changes need to be made.

Now, I didn't notice that getCount, getList, and increment don't take
arguments, so you either need to provide explicit type signatures or
set NoMonomorphismRestriction. If you do the latter and load the code
into ghci, you get:

*Main :t runCmd
runCmd :: (MonadState PD m, MonadIO m) = [Char] - m ()


-- 
Dave Menendez d...@zednenem.com
http://www.eyrie.org/~zednenem/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Finally tagless - stuck with implementation?of?lam

2009-10-05 Thread Chung-chieh Shan
Don Stewart d...@galois.com wrote in article 
20091006031054.gb18...@whirlpool.galois.com in gmane.comp.lang.haskell.cafe:
 ccshan:
  (Section 5 of our (JFP) paper addresses both CBN and CBV.)
 Do you have a link to the paper?

Sorry, here it is.
http://www.cs.rutgers.edu/~ccshan/tagless/jfp.pdf

-- 
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
Here's a souvenir of it. He made me write this down so I'd remember
to get this book and read it. Transcendent Speculations on Apparent
Design in the Fate of the Individual, that's a mouthful isn't it. I
wrote this down at gun-point. - Gaddis

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe