Beginners Digest, Vol 3, Issue 12
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Why is there no notion of a one-tuple (e.g., a '([])' as opposed to a '[]') in Haskell? (Jason Dusek) 2. Re: Why is there no notion of a one-tuple (e.g., a '([])' as opposed to a '[]') in Haskell? (Benjamin L.Russell) 3. Re: Why is there no notion of a one-tuple (e.g., a '([])' as opposed to a '[]') in Haskell? (Aaron Denney) 4. Module import problem (Casey Rodarmor) 5. Re: Module import problem (Chry Cheng) 6. Re: Module import problem (Casey Rodarmor) 7. Re: Module import problem (Christian Cheng) 8. Re: Module import problem ( Chadda? Fouch? ) -- Message: 1 Date: Thu, 25 Sep 2008 00:56:26 -0700 From: Jason Dusek [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] Why is there no notion of a one-tuple (e.g., a '([])' as opposed to a '[]') in Haskell? To: Benjamin L. Russell [EMAIL PROTECTED] Cc: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=UTF-8 How is a 1-tuple different from a value? If we think of tuple types as product types, then the 1-ary product is a simple type -- and 1-ary tuples of values are simple values. In Python, tuples really are like lists -- to the point of being mapable, iterable, c. In Haskell, lists and tuples share very little. -- _jsn -- Message: 2 Date: Thu, 25 Sep 2008 19:14:45 +0900 From: Benjamin L.Russell [EMAIL PROTECTED] Subject: [Haskell-beginners] Re: Why is there no notion of a one-tuple (e.g., a '([])' as opposed to a '[]') in Haskell? To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii On Wed, 24 Sep 2008 21:27:37 -0400, [EMAIL PROTECTED] wrote: G'day all. Quoting Benjamin L.Russell [EMAIL PROTECTED]: Haskell doesn't have a notion of a one-element tuple. Why not? As noted by others, there's no syntactic space for them. Perhaps more crucially, it's hard to see where such a thing would be useful. The 2-tuple (i.e. pair) is a categorical product, and can be used to carry around two things where you would normally only have space for one. The 0-tuple (i.e. void) is a categorical terminal object, and can be used to fill in space in a parametric data structure where no annotation is actually needed. One reason why they're provided in the Prelude is so that standard functions can do operations on them. It's hard to see where a standard function would use a generic 1-tuple. Generally speaking, if you need a type-checked 1-tuple, you almost certainly don't want a generic one. So, basically generic one-element tuples don't exist because they're not needed, and there is no elegant way to represent them syntactically. That makes sense. Nevertheless, I can't help feeling that Haskell could perhaps been made even more elegant if some alternative tuple notation not conflicting with parentheses had been used; e.g., '{}' (braces) (please forgive me if braces are already used for some other purpose of which I am not aware). Then, for example, we could have the following: {} (a unit, or void), {{}} (a one-tuple), {{{}}} (a one-tuple consisting of a one-tuple), (a one-tuple consisting of a one-tuple consisting of a one-tuple), ... We could then come up with an n-depth-ordering on tuples, as opposed to an ordering on n-tuples. While perhaps not immediately useful, this ordering would have an interesting structure, and perhaps lead to some kind of mathematics of n-depth-orderings, which could be even more interesting, and which could be expressed in Haskell. -- Benjamin L. Russell -- Message: 3 Date: Wed, 24 Sep 2008 23:26:33 + (UTC) From: Aaron Denney [EMAIL PROTECTED] Subject: [Haskell-beginners] Re: Why is there no notion of a one-tuple (e.g., a '([])' as opposed to a '[]') in Haskell? To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii On 2008-09-24, Benjamin L.Russell [EMAIL PROTECTED] wrote: Haskell doesn't have a notion of a one-element tuple. Why not? In addition to the syntactic nightmare mentioned, or the possible loss of parenthesized expressions, it's just plain not necessary. Aside from strictness, a one-tuple is isomorphic to the element inside. We like category theory, so we ignore trivial isomorphisms. -- Aaron Denney -- -- Message: 4 Date: Sun, 28 Sep 2008
Beginners Digest, Vol 4, Issue 1
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Exposing Ratio data constructor ( Chadda? Fouch? ) 2. Perfect numbers (Matthew Williams) 3. Re: Perfect numbers (wman) 4. Re: Perfect numbers (Jason Dusek) 5. Re: Perfect numbers (wman) -- Message: 1 Date: Mon, 29 Sep 2008 21:03:50 +0200 From: Chadda? Fouch? [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] Exposing Ratio data constructor To: Casey Rodarmor [EMAIL PROTECTED] Cc: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=ISO-8859-1 2008/9/29 Casey Rodarmor [EMAIL PROTECTED]: invertRatio r = denominator r % numerator Ratio is an instance of Fractional, which means : invertRation = recip ou invert f = 1 / f (probably the default definition of recip anyway). Is there any way to avoid this, while still letting the user benefit from the nice pattern matching syntax that exposing the data constructor allows? To this more general question : allow the convenience of pattern matching while keeping a datatype abstract, the latest GHC (6.10) bring a new extension called view pattern, it may not be ideal but it should be pretty useful in this direction. http://hackage.haskell.org/trac/ghc/wiki/ViewPatterns -- Jedaï -- Message: 2 Date: Thu, 2 Oct 2008 05:45:01 +0100 From: Matthew Williams [EMAIL PROTECTED] Subject: [Haskell-beginners] Perfect numbers To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii Hi Guys, I'm new to Haskell and I was wondering if you can help me: One of the first program's I tend to write when I'm looking at a new language is a program to generate a list of perfect numbers: --My First Perfect Number Generator factors :: Integer - [Integer] factors x = [z | z - [1..x-1], x `mod` z == 0] is_perfect :: Integer - Bool is_perfect x = if sum(factors x) == x then True else False do_perfect :: [Integer] - [Integer] do_perfect x = [z |z - x, is_perfect z ] Then to run it: do_perfect [1..9000] I'm using GHC to run it. My problem / question is this: It's running quite a lot slower than equivalent programs in erlang and python. I suspect it's down to the way I've written it. Any thoughts (or comments in general) Many thanks Matt __ This email may contain privileged or confidential information, which should only be used for the purpose for which it was sent by Xyratex. No further rights or licenses are granted to use such information. If you are not the intended recipient of this message, please notify the sender by return and delete it. You may not use, copy, disclose or rely on the information contained in it. Internet email is susceptible to data corruption, interception and unauthorised amendment for which Xyratex does not accept liability. While we have taken reasonable precautions to ensure that this email is free of viruses, Xyratex does not accept liability for the presence of any computer viruses in this email, nor for any losses caused as a result of viruses. Xyratex Technology Limited (03134912), Registered in England Wales, Registered Office, Langstone Road, Havant, Hampshire, PO9 1SA. The Xyratex group of companies also includes, Xyratex Ltd, registered in Bermuda, Xyratex International Inc, registered in California, Xyratex (Malaysia) Sdn Bhd registered in Malaysia, Xyratex Technology (Wuxi) Co Ltd registered in The People's Republic of China and Xyratex Japan Limited registered in Japan. __ -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20081002/fb1929bb/attachment-0001.htm -- Message: 3 Date: Thu, 2 Oct 2008 07:25:17 +0200 From: wman [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] Perfect numbers To: Matthew Williams [EMAIL PROTECTED] Cc: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=iso-8859-1 First step would probably be using Ints instead of Integers. On Thu, Oct 2, 2008 at 6:45 AM, Matthew Williams [EMAIL PROTECTED] wrote: Hi Guys, I'm new to Haskell and I was wondering if you can help me: One of the first program's I tend to write when I'm looking at a new language is a program to generate a list of perfect numbers: --My
Beginners Digest, Vol 4, Issue 6
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Problems with ghc (Christian Maeder) 2. Re: fix (Justin Bailey) 3. Mathematical Blundering (Jeffrey Drake) 4. RE: Mathematical Blundering (Paul Johnston) 5. solved: implementation dependent (was Re: [Haskell-beginners] betterway to create Array defined on all indices (Larry Evans) 6. Re: better way to create Array defined on allindices (Daniel Fischer) 7. HaXml.SAX successfully parses a malformed XMLdocument (David Frey) 8. IO Problem (Jamie McCloskey) 9. Re: IO Problem (Daniel Fischer) -- Message: 1 Date: Wed, 15 Oct 2008 16:06:33 +0200 From: Christian Maeder [EMAIL PROTECTED] Subject: [Haskell-beginners] Re: Problems with ghc To: Paul Johnston [EMAIL PROTECTED] Cc: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=ISO-8859-1 Paul Johnston wrote: [EMAIL PROTECTED]:~/haskell/aht/3$ ghc -L=/usr/local/lib/ -o Haq --make Haq.hs [1 of 1] Compiling Main ( Haq.hs, Haq.o ) Linking Haq ... [EMAIL PROTECTED]:~/haskell/aht/3$ ./Haq Bother Haq! BotherOr not! [EMAIL PROTECTED]:~/haskell/aht/3$ Tried putting /usr/local/lib in $LD_LIBRARY_PATH but that didn't seem to work, pity. Anyway many, many thanks I think setting LIBRARY_PATH would work. Cheers Christian -- Message: 2 Date: Wed, 15 Oct 2008 16:02:50 -0700 From: Justin Bailey [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] fix To: Matthew J. Williams [EMAIL PROTECTED] Cc: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=ISO-8859-1 n decreases on each step of the recursion, which will allow it to terminate. You need to expand AND substitute arguments: fix (\rec n - if n == 0 then 1 else n * rec (n-1)) 5 fix (\rec 5 - if 5 == 0 then 1 else n * rec (5 -1)) fix (\rec 5 - if 5 == 0 then 1 else n * (fix (\rec 4 - if 4 == 0 then 1 else 4 * rec (3-1 And so on. On Wed, Oct 15, 2008 at 3:51 PM, Matthew J. Williams [EMAIL PROTECTED] wrote: hello listers, a few days ago A fellow lister sent me the following link: http://en.wikibooks.org/wiki/Haskell/Fix_and_recursion The 'fix' function is interesting to say the least. There is one example that I've had difficulty expanding: fix (\rec n - if n == 0 then 1 else n * rec (n-1)) 5 120 My interpretation: fix (\rec n - if n == 0 then 1 else n * rec (n-1)) 5 ((\rec n - if n == 0 then 1 else n * rec (n-1)) (fix (\rec n - if n == 0 then 1 else n * rec (n-1)) )) 5 . . . Yet, it does not quite explain how 'fix' does not result in infinite recursion. Sincerely Matthew J. Williams ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- Message: 3 Date: Thu, 16 Oct 2008 04:46:47 -0400 From: Jeffrey Drake [EMAIL PROTECTED] Subject: [Haskell-beginners] Mathematical Blundering To: Haskell Beginners beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain I have defined myself a set of functions to test: fact 1 = 1 fact n = n * (fact $ n - 1) sine x = x - (x^3/(fact 3)) + (x^5/(fact 5)) - (x^7/(fact 7)) Where my code is 'sine' and the prelude's is sin: *Main sine 1 0.841468253968254 *Main sin 1 0.8414709848078965 *Main sine 2 0.9079365079365079 *Main sin 2 0.9092974268256817 *Main sine 3 9.107142857142847e-2 *Main sin 3 0.1411200080598672 *Main sine 4 -1.3841269841269837 *Main sin 4 -0.7568024953079282 After 2 they seem to diverge rather rapidly, and I am not sure why. Any ideas? I would have thought that 4 terms would have been enough. - Jeff. -- Message: 4 Date: Thu, 16 Oct 2008 09:57:39 +0100 From: Paul Johnston [EMAIL PROTECTED] Subject: RE: [Haskell-beginners] Mathematical Blundering To: Jeffrey Drake [EMAIL PROTECTED],Haskell Beginners beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=iso-8859-1 Bit of basic maths. You are using a power series to approximate sine This works by taking an expansion about a fixed point, usually zero. It only works well around that point. If you get far away it works badly. You need to exploit the cyclic nature of the trignometrical functions i.e. Sin x = sin ((2 * pi) + x) = sin ((4 * pi) + x)
Beginners Digest, Vol 4, Issue 7
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: IO Problem (Brent Yorgey) 2. Re: Mathematical Blundering (Andrew Sackville-West) 3. requested module name differs from name found in interface file (Larry Evans) 4. A Pascal-like Language Compiler (Pranesh Srinivasan) 5. Re: A Pascal-like Language Compiler ( Joel Bj?rnson ) 6. Re: requested module name differs from name foundin interface file (Larry Evans) -- Message: 1 Date: Fri, 17 Oct 2008 14:11:55 -0400 From: Brent Yorgey [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] IO Problem To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii On Fri, Oct 17, 2008 at 07:58:45PM +1300, Jamie McCloskey wrote: All this creates a whole load of functions with IO, even though it should not be necessary. What I would like to know, is how I can avoid this, possibly by modifying exec to just take a State. The short answer is: it IS necessary. Think about what exec does, for instance. It takes a Program and an initial State and does... what? Executes the program, which might result in some things getting printed to the screen or some input being read from the keyboard. That is, exec can have some I/O effects. Therefore, exec's return type must be an IO value. The same goes for all the other functions you mentioned. This is a feature, not a bug --- the type of a function tells you precisely whether it can possibly have any I/O effects. If the return type is (IO something), then it can; if the return type does not involve IO, then it is *guaranteed*[1] that it cannot have any I/O effects. -Brent [1] Except for that pesky unsafePerformIO. But you should never use that, unless you really absolutely know what you are doing and why. -- Message: 2 Date: Fri, 17 Oct 2008 16:52:28 -0700 From: Andrew Sackville-West [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] Mathematical Blundering To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii On Thu, Oct 16, 2008 at 09:57:39AM +0100, Paul Johnston wrote: Bit of basic maths. You are using a power series to approximate sine This works by taking an expansion about a fixed point, usually zero. It only works well around that point. If you get far away it works badly. You need to exploit the cyclic nature of the trignometrical functions i.e. Sin x = sin ((2 * pi) + x) = sin ((4 * pi) + x) Essentially consider the shift in multiples of 2 * pi and calculate the value of x nearest to zero. See http://en.wikipedia.org/wiki/Taylor_series The diagram on the top right is very instructive. how appropriate. We're doing this in math right now ;) ISTM that OP should take x modulo pi and (per the wiki diagram) a seven term series to get a nice usable sine function. (and don't forget to watch for the sign (nopun) of the result) fact 1 = 1 fact x = x * (fact $ x - 1) term n x = (-1)**n * (theta**(2*n + 1) / fact(2*n + 1)) where theta = pi * ((x / pi) - xTrunc) * sign xTrunc = fromIntegral $ truncate (x/pi) sign = (-1)**xTrunc sine x = sum $ take 7 [term n x | n-[0..]] Wow, that took me a lot longer to figure out because of all the mixing of numeric types. The critical part was fromIntegral in the poorly name xTrunc function. but it looks pretty accurate. *Main maximum [sine x - sin x | x-[1..100]] 1.2652798913048713e-5 and it's easy to boost the accuracy by taking more terms in the series. taking 9: *Main maximum [sine x - sin x | x-[1..100]] 1.1683279538265978e-8 taking 11: *Main maximum [sine x - sin x | x-[1..100]] 4.694897248747054e-12 I'm sure there must be a better way to get x modulo pi, but I don't know enough... I'd love some feedback on my solution both from a math and a haskell perspective. A Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jeffrey Drake Sent: Thursday, October 16, 2008 9:47 AM To: Haskell Beginners Subject: [Haskell-beginners] Mathematical Blundering I have defined myself a set of functions to test: fact 1 = 1 fact n = n * (fact $ n - 1) sine x = x - (x^3/(fact 3)) + (x^5/(fact 5)) - (x^7/(fact 7)) Where my code is 'sine' and the prelude's is sin: *Main sine 1 0.841468253968254 *Main sin 1 0.8414709848078965 *Main sine 2 0.9079365079365079 *Main sin 2 0.9092974268256817 *Main sine 3 9.107142857142847e-2
Beginners Digest, Vol 4, Issue 9
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: what type is 'Val 9' when 'Val Int' a ctor for 'Expr e'? (Jason Dusek) 2. Re: what type is 'Val 9' when 'Val Int' a ctor for 'Expr e'? (Antoine Latter) 3. Re: A Pascal-like Language Compiler (Pranesh Srinivasan) 4. Re: what type is 'Val 9' when 'Val Int' a ctor for 'Expr e'? (Daniel Fischer) 5. Type problems with IOArray (Xuan Luo) 6. Re: Type problems with IOArray (Alexander Dunlap) 7. Re: what type is 'Val 9' when 'Val Int' a ctor for 'Expr e'? (Larry Evans) -- Message: 1 Date: Wed, 22 Oct 2008 14:10:05 -0700 From: Jason Dusek [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] what type is 'Val 9' when 'Val Int' a ctorfor 'Expr e'? To: Larry Evans [EMAIL PROTECTED] Cc: Beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=UTF-8 Can you explain why you think you need that annotation? I can't see an ambiguous interpretation of your code. -- _jsn -- Message: 2 Date: Wed, 22 Oct 2008 16:44:07 -0500 From: Antoine Latter [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] what type is 'Val 9' when 'Val Int' a ctorfor 'Expr e'? To: Jason Dusek [EMAIL PROTECTED] Cc: Beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=ISO-8859-1 On Wed, Oct 22, 2008 at 4:10 PM, Jason Dusek [EMAIL PROTECTED] wrote: Can you explain why you think you need that annotation? I can't see an ambiguous interpretation of your code. The confusion is that the 'Val' constructor is for the 'Expr' type, which has a phantom type parameter in its type constructor. Can you load that up into GHCi and type: :t val_9 which should cause GHCi to print out what it thinks the type of that expression is. -Antoine -- Message: 3 Date: Thu, 23 Oct 2008 03:48:24 +0530 From: Pranesh Srinivasan [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] A Pascal-like Language Compiler To: Joel Bj?rnson [EMAIL PROTECTED] Cc: Hasekll - Beginners beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=ISO-8859-1 Hey all, Thanks to everyone for replying. I was severly caught up with work for the last two days. The link Larry gave for the lookahead states seems very nice :). But I am not sure if Ill be looking to calculate the lookahead states myself, or let BNFC do the job? In either case, I think merely printing the line number where the error occured should do in the worse case. It will be exciting to have nice error messages though. I am starting to reliase the advantage of pattern matching being present, like Chris had said. I mean it definitely beats maintaining and checking a flag, the way you would do it in C :) Definitely not, just go for it. In the IPL course @ UU we implemented Thanks, Chris :). 1. Parse input file into an abstract syntax tree representation. 2. Perform type checking on your syntax tree. 3. Transform the syntax tree using re-write rules and optimisations. 4. Pretty print the syntax tree in order to output code of your target language. That seems like a very nice scheme to follow. I had a similar method in mind. Step 3 is what I am really worried about. How easy/difficult will it be in a pure func language, to transform the sytnax tree. I have to take a deeper look at BNFC. But from an initial look, it seems way too powerful for me to use? At least as powerful as yacc. And that with Haskell, should give me a very good toolset-advantage? @Chris : The ipl course website, seems very helpful, especially some of the lectures on abstract syntax. -- Pranesh Srinivasan, Third Year Student, Computer Science Engineering, Indian Institute of Technology - Madras. http://spranesh.googlepages.com http://www.cse.iitm.ac.in/~spranesh/ -- Message: 4 Date: Thu, 23 Oct 2008 02:52:39 +0200 From: Daniel Fischer [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] what type is 'Val 9' when 'Val Int' a ctorfor 'Expr e'? To: Antoine Latter [EMAIL PROTECTED], Jason Dusek [EMAIL PROTECTED] Cc: Beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=iso-8859-1 Am Mittwoch, 22. Oktober 2008 23:44 schrieb Antoine Latter: On Wed, Oct 22, 2008 at 4:10 PM, Jason Dusek [EMAIL PROTECTED] wrote: Can you explain why you think you need that
Beginners Digest, Vol 4, Issue 10
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: what type is 'Val 9' when 'Val Int' a ctor for 'Expr e'? (Daniel Fischer) 2. how to define a user datatype consisting of instances of String? (Benjamin L.Russell) 3. Re: how to define a user datatype consisting of instances of String? (Benjamin L.Russell) 4. Re: how to define a user datatype consisting of instances of String? (Benjamin L.Russell) 5. Re: how to define a user datatype consisting of instances of String? (Daniel Fischer) 6. Re: how to define a user datatype consisting of instances of String? (Benjamin L.Russell) 7. Re: A Pascal-like Language Compiler ( Joel Bj?rnson ) -- Message: 1 Date: Thu, 23 Oct 2008 06:10:21 +0200 From: Daniel Fischer [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] what type is 'Val 9' when 'Val Int' a ctorfor 'Expr e'? To: Larry Evans [EMAIL PROTECTED] Cc: Beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=iso-8859-1 Am Donnerstag, 23. Oktober 2008 05:36 schrieb Larry Evans: Thanks Deaniel. The fog in my head begins to clear. I took Antoine's suggestion and got: ---cut here --- GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. Prelude :load /home/evansl/prog_dev/haskell/my-code/uniplate.try.phantom.hs [1 of 1] Compiling Main ( /home/evansl/prog_dev/haskell/my-code/uniplate.try.phantom.hs, interpreted ) Ok, modules loaded: Main. *Main let val_9 = Val 9 Loading package mtl-1.1.0.0 ... linking ... done. Loading package array-0.1.0.0 ... linking ... done. Loading package containers-0.1.0.1 ... linking ... done. Loading package uniplate-1.2.0.1 ... linking ... done. *Main :t val_9 val_9 :: Expr e *Main print val_9 Val 9 *Main ---cut here--- I guess the phantom type mentioned in Antoine's post is the e in: val_9::Expr e ? Exactly. That type is never used in any value of type (Expr e), therefore it is called a 'phantom' type. It only serves as a tag to prevent mixing Expr's with different type parameters. Cheers, Daniel -- Message: 2 Date: Thu, 23 Oct 2008 15:07:09 +0900 From: Benjamin L.Russell [EMAIL PROTECTED] Subject: [Haskell-beginners] how to define a user datatype consisting of instances of String? To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii How is it possible to define a user datatype consisting of instances of String? Suppose I am preparing a party for wine connoisseurs, and want to define the following data types: data Wine = Red | White data Red = Merlot data White = Sauvignon Blanc data Entree = pork | chicken | tuna data SideDish = garlic bread | mozzarella sticks | caviar Then, I want to write a Haskell function that takes two lists; e.g., [pork, chicken, tuna] and [garlic bread, mozzarella sticks, caviar] and that constructs a three-tuple of the following type: (Entree, SideDish, Wine) such that which Wine is chosen depends on the particular combination of Entree and SideDish, with respect to the following rules: (pork, garlic bread) - (pork, garlic bread, Merlot) (pork, mozzarella sticks) - (pork, mozzarella sticks, Merlot) (pork, caviar) - (pork, Beluga, Sauvignon Blanc) (chicken, garlic bread) - (chicken, garlic bread, Merlot) (chicken, mozzarella sticks) - (chicken, mozzarella sticks, Sauvignon Blanc) (chicken, caviar) - (chicken, caviar, Merlot) (tuna, garlic bread) - (tuna, garlic bread, Sauvignon Blanc) (tuna, mozzarella sticks) - (tuna, mozzarella sticks, Merlot) (tuna, caviar) - (tuna, caviar, Merlot) So far, I have written the following Haskell code: module Wine where data Wine = Red | White data Red = Merlot data White = Sauvignon Blanc data Entree = pork | chicken | tuna data SideDish = garlic bread | mozzarella sticks | caviar wine :: [Entree] - [SideDish] - [(Entree, SideDish, Wine)] wine entree sidedish | entree == pork = | sidedish == garlic bread = (pork, garlic bread, Merlot) | sidedish == mozzarella sticks = (pork, mozzarella sticks, Merlot) | sidedish == caviar = (pork, caviar, Sauvignon Blanc) | entree == chicken = | sidedish == garlic bread = (chicken, garlic bread, Merlot) | sidedish == mozzarella sticks = (chicken, mozzarella sticks, Sauvignon Blanc) | sidedish == caviar= (chicken, caviar,
Beginners Digest, Vol 4, Issue 13
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Re: pattern for tree traversel with a state (Andreas-Christoph Bernstein) 2. Re: Re: pattern for tree traversel with a state (Jan Jakubuv) 3. Re: Type problems with IOArray (apfelmus) 4. Re: Re: pattern for tree traversel with a state (Brent Yorgey) 5. Function composition with more than 1 parameter (Glurk) 6. Re: Function composition with more than 1parameter (Jason Dusek) 7. Re: Function composition with more than 1parameter (apfelmus) 8. Re: Function composition with more than 1 parameter (Glurk) 9. Re: Re: Function composition with more than 1parameter (Daniel Fischer) -- Message: 1 Date: Thu, 23 Oct 2008 19:38:10 +0200 From: Andreas-Christoph Bernstein [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] Re: pattern for tree traversel with a state To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=ISO-8859-1; format=flowed apfelmus wrote: Andreas-Christoph Bernstein wrote: Is there a pattern for tree traversal with a state ? I am developing a small scenegraph represented by a tree. To draw a scenegraph one traverses over the graph starting with a global state. Inner Nodes can overwrite the inherited state for their subtree (e.g. Transformations are accumulated). The accumulated state is then either used immediately to draw the geometry in the leaf nodes, or a secondary data structure is build. This secondary data structure (a list or a tree) can then be sorted for optimal drawing performance. So i want to do the second and create a list of all leaves with the accumulated global state. To illustrate my problem i appended some code. The idea similar applies to a scenegraph. So my Question is: Is there already a pattern for traversal with a state ? Yes. I'm not sure whether state is really necessary for your problem, i.e. whether there is a more elegant formulation, but your algorithm fits a well-known pattern, namely the one in Data.Traversable import Data.Traversable import Data.Foldable import qualified Control.Monad.State data BTree a = Fork a (BTree a) (BTree a) | Leaf a deriving Show -- main functionality instance Traversable BTree where traverse f (Leaf x) = Leaf $ f x traverse f (Fork x l r) = Fork $ f x * traverse f l * traverse f r -- derived examples instance Foldable BTree where foldMap = foldMapDefault instance Functor BTree where fmap= fmapDefault flattenTree = toList -- state example data StateMod = ModInt | ModString | ModNop deriving Show type State= (Int, String) modState :: StateMod - State - State modState ModInt(x,w) = (x+1,w) modState ModNops = s modState ModString (x,w) = (x,'b':w) startState = (0,a) newTree :: BTree StateMod - BTree State newTree = flip evalState startState . Data.Traversable.mapM (modify' . modState) where modify' f = Control.Monad.State.modify f Control.Monad.State.get Hi, Thanks for the quick reply. But it is not quite what i expect. If i apply your solution to an exampletree i get the following result: tree :: BTree StateMod tree = Fork ModNop (Fork ModInt (Leaf ModInt) (Leaf ModNop)) (Leaf ModNop) flattenTree (newTree tree ) which produces: [(0,a),(1,a),(2,a),(2,a),(2,a)] But what i need is [(0,a),(1,a),(2,a),(1,a),(0,a)] So state changes should affect only their subtree, not the rest of the tree to the right. Kind regards, Andreas -- Message: 2 Date: Thu, 23 Oct 2008 23:47:43 +0100 From: Jan Jakubuv [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] Re: pattern for tree traversel with a state To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=ISO-8859-1 2008/10/23 Andreas-Christoph Bernstein [EMAIL PROTECTED]: apfelmus wrote: But what i need is [(0,a),(1,a),(2,a),(1,a),(0,a)] So state changes should affect only their subtree, not the rest of the tree to the right. It seems to me that you are looking for the Reader monad. Try the following: import Control.Monad.Reader t :: (a - b - b) - BTree a - Reader b (BTree b) t f (Leaf x) = do s - ask return (Leaf (f x s)) t f (Fork x l r) = do s - ask l' - local (f x) (t f l) r'
Beginners Digest, Vol 4, Issue 15
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. eval command? (Alex Shearn) 2. Re: eval command? (Brandon S. Allbery KF8NH) 3. Re: eval command? (Brent Yorgey) 4. evaluation of expressions [was Re: eval command?] (Andrew Sackville-West) 5. Re: evaluation of expressions [was Re: eval command?] (Brandon S. Allbery KF8NH) 6. gtk2hs treeViewSetReorderable ([EMAIL PROTECTED]) 7. Re: evaluation of expressions [was Re: eval command?] (Tony Hannan) 8. Re: gtk2hs treeViewSetReorderable ([EMAIL PROTECTED]) 9. Re: evaluation of expressions [was Re: eval command?] (Andrew Sackville-West) -- Message: 1 Date: Mon, 27 Oct 2008 21:33:21 + From: Alex Shearn [EMAIL PROTECTED] Subject: [Haskell-beginners] eval command? To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hey all - I've been trying to write an IRC bot following the guide on the wiki, and we (those of us on the channel) were trying to get it to evaluate commands. So far, we have this for eval stuff, but is there anyway to specify a parse in haskell sort of thing? [code] -- Dispatch a command eval :: String - Net () eval !endbot = write QUIT :Exiting io (exitWith ExitSuccess) eval x | !haskbot `isPrefixOf` x = privmsg (drop 9 x) eval _ = return () -- ignore everything else [/code] is there anyway to do something like: eval !eval `isPrefixOf` x = eval blah ? if this isn't beginners' stuff, let me know, i'll repost to the main mailing list. Many thanks, Alex Shearn -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. -- Message: 2 Date: Mon, 27 Oct 2008 19:00:00 -0400 From: Brandon S. Allbery KF8NH [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] eval command? To: [EMAIL PROTECTED] Cc: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes On 2008 Oct 27, at 17:33, Alex Shearn wrote: Hey all - I've been trying to write an IRC bot following the guide on the wiki, and we (those of us on the channel) were trying to get it to evaluate commands. So far, we have this for eval stuff, but is there anyway to specify a parse in haskell sort of thing? No, although you could fake it with the GHC-API (which basically means your bot has all of GHC built into it). In any case, that's not really a good idea; consider what damage could be done by arbitrary code. A better idea is to link the code into a small program with a very restricted environment and run that with a timeout. See http://code.haskell.org/lambdabot/Plugin/Eval.hs. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH -- Message: 3 Date: Mon, 27 Oct 2008 19:45:26 -0400 From: Brent Yorgey [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] eval command? To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii On Mon, Oct 27, 2008 at 07:00:00PM -0400, Brandon S. Allbery KF8NH wrote: On 2008 Oct 27, at 17:33, Alex Shearn wrote: Hey all - I've been trying to write an IRC bot following the guide on the wiki, and we (those of us on the channel) were trying to get it to evaluate commands. So far, we have this for eval stuff, but is there anyway to specify a parse in haskell sort of thing? No, although you could fake it with the GHC-API (which basically means your bot has all of GHC built into it). In any case, that's not really a good idea; consider what damage could be done by arbitrary code. A better idea is to link the code into a small program with a very restricted environment and run that with a timeout. See http://code.haskell.org/lambdabot/Plugin/Eval.hs. Brandon is right that this is difficult and tricky -- but fortunately, someone else has already done the hard work for you! Take a look at the mueval package [1], which should allow you to do what you want. -Brent [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/mueval -- Message: 4 Date: Mon, 27 Oct 2008 20:25:20 -0700 From: Andrew Sackville-West [EMAIL PROTECTED] Subject: [Haskell-beginners] evaluation of expressions
Beginners Digest, Vol 5, Issue 1
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: evaluation of expressions [was Re: evalcommand?] (Tillmann Rendel) 2. Re: evaluation of expressions [was Re: eval command?] (Andrew Sackville-West) 3. Re: evaluation of expressions [was Re: eval command?] (Andrew Sackville-West) 4. Control.Monad.State: State CTOR unneeded to create a State? (Larry Evans) 5. Re: Control.Monad.State: State CTOR unneeded to create a State? (Antoine Latter) 6. Re: Control.Monad.State: State CTOR unneeded to create a State? (Larry Evans) 7. Re: Control.Monad.State: State CTOR unneeded to create a State? (Luca Padovani) 8. Re: Control.Monad.State: State CTOR unneeded to create a State? (Brandon S. Allbery KF8NH) -- Message: 1 Date: Wed, 29 Oct 2008 09:27:32 +0100 From: Tillmann Rendel [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] evaluation of expressions [was Re: evalcommand?] To: Andrew Sackville-West [EMAIL PROTECTED] Cc: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=ISO-8859-15; format=flowed Andrew Sackville-West schrieb: this raises a question for me, being a bit of a schemer. Is there any parallel in haskell to the data is code model of the lisp family? No. My initial impression is no, that you'd have to parse it as an expression and evaluate it as you would in regular imperative languages. I'd love to hear otherwise. I don't see how code is data is connected to imperative vs. purely functional. After all, lisp co. are not purely functional, but feature code is data. Another well-known symbolic language, which allows to treat code as data and vice versa, is prolog. Since Haskell features algebraic data types, and a reasonable flexible syntax, you do not need to do any parsing. Instead, you can write down the AST of the embedded language directly as part of your Haskell program. But you have to write an evaluator. With pattern matching, that is often very easy, though. Tillmann -- Message: 2 Date: Wed, 29 Oct 2008 07:02:46 -0700 From: Andrew Sackville-West [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] evaluation of expressions [was Re: evalcommand?] To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii On Wed, Oct 29, 2008 at 09:27:32AM +0100, Tillmann Rendel wrote: Andrew Sackville-West schrieb: this raises a question for me, being a bit of a schemer. Is there any parallel in haskell to the data is code model of the lisp family? No. My initial impression is no, that you'd have to parse it as an expression and evaluate it as you would in regular imperative languages. I'd love to hear otherwise. I don't see how code is data is connected to imperative vs. purely functional. After all, lisp co. are not purely functional, but feature code is data. Another well-known symbolic language, which allows to treat code as data and vice versa, is prolog. I didn't mean to connect the concept to imperative vs. functional. Since Haskell features algebraic data types, and a reasonable flexible syntax, you do not need to do any parsing. Instead, you can write down the AST of the embedded language directly as part of your Haskell program. But you have to write an evaluator. With pattern matching, that is often very easy, though. looks like I'm off to read about Template Haskell. thanks to all. A -- next part -- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/beginners/attachments/20081029/7cc44d4a/attachment-0001.bin -- Message: 3 Date: Wed, 29 Oct 2008 07:48:59 -0700 From: Andrew Sackville-West [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] evaluation of expressions [was Re: evalcommand?] To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii On Wed, Oct 29, 2008 at 07:02:46AM -0700, Andrew Sackville-West wrote: On Wed, Oct 29, 2008 at 09:27:32AM +0100, Tillmann Rendel wrote: ... Since Haskell features algebraic data types, and a reasonable flexible syntax, you do not need to do any parsing. Instead, you can write down the AST of the embedded language directly as part of your
Beginners Digest, Vol 5, Issue 2
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Control.Monad.State: State CTOR unneeded to create a State? (Brent Yorgey) 2. Weighted average (Michael Snoyman) 3. Re: Weighted average (Daniel Fischer) 4. Re: Weighted average (Michael Snoyman) 5. Re: Weighted average (Daniel Fischer) 6. Re: Weighted average (Michael Snoyman) 7. Re: Weighted average (apfelmus) 8. Tab complement (gerry xiao) -- Message: 1 Date: Sat, 1 Nov 2008 15:43:55 -0400 From: Brent Yorgey [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] Control.Monad.State: State CTOR unneededto create a State? To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii On Sat, Nov 01, 2008 at 11:23:38AM -0500, Larry Evans wrote: put (n+1) AFAICT, with the preceding |n - get|, this means: put (get+1) and since the get has type, |State Int Int|, and there's not + operator defined on that type (because the following: Others have explained in more detail, let me just state this simply to hopefully clear up the main point of confusion: let x = y and x - y are *not* the same. In the first case, x is just a name for y, and x and y can be used interchangeably. In the second case, x is bound to *the result of* the action y. So x and y cannot be used interchangeably. -Brent -- Message: 2 Date: Mon, 3 Nov 2008 13:41:26 -0800 From: Michael Snoyman [EMAIL PROTECTED] Subject: [Haskell-beginners] Weighted average To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=utf-8 Hi everyone, I'm trying to set up some type safe functions for doing weighted averages and sum of products. The example I give below is to try and calculate the average miles per gallon for a collections of vehicles. Unfortunately, I am unable to get my weightedAverage function to work, seemingly due to an ambiguity for which instance to use. I think that the issue is that my class Multiplicable should only have two parameters, as opposed to the three it currently has. However, I can't figure out how to get that to work. Any help is greatly appreciated. Thank you, Michael -- {-# LANGUAGE MultiParamTypeClasses #-} import Prelude hiding (sum, product) class Addable a where add :: a - a - a zero :: a sum :: [a] - a sum = foldr add zero class Multiplicable a b c where mult :: a - b - c product :: [a] - [b] - [c] product x y = map (\(x1, y1) - x1 `mult` y1) $ zip x y sumProduct :: (Addable c, Multiplicable a b c) = [a] - [b] - c sumProduct x y = sum $ product x y weightedAverage x y = (sumProduct y x) `divide` (sum y) class Dividable a b c where divide :: c - a - b newtype MilesPerGallon = MilesPerGallon Double deriving Show newtype Gallon = Gallon Double deriving Show newtype Mile = Mile Double deriving Show instance Addable Gallon where add (Gallon x) (Gallon y) = Gallon $ x + y zero = Gallon 0 instance Addable Mile where add (Mile x) (Mile y) = Mile $ x + y zero = Mile 0 instance Multiplicable Gallon MilesPerGallon Mile where mult (Gallon x) (MilesPerGallon y) = Mile $ x * y instance Dividable Gallon MilesPerGallon Mile where divide (Mile x) (Gallon y) = MilesPerGallon $ x / y milesPerGallon :: [MilesPerGallon] milesPerGallon = map MilesPerGallon [35, 25, 29, 20, 52] gallons :: [Gallon] gallons = map Gallon [500, 190, 240, 100, 600] totalGallons :: Gallon totalGallons = sum gallons totalMiles :: Mile totalMiles = sumProduct gallons milesPerGallon totalMilesPerGallon :: MilesPerGallon totalMilesPerGallon = totalMiles `divide` totalGallons -- I would like some way to get the following line to replace the previous --totalMilesPerGallon = weightedAverage milesPerGallon gallons main = do putStrLn $ Total gallons of gas used: ++ show totalGallons putStrLn $ Total miles traveled: ++ show totalMiles putStrLn $ Average miles per gallon: ++ show totalMilesPerGallon -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20081103/9bf23093/attachment-0001.htm -- Message: 3 Date: Mon, 3 Nov 2008 23:55:37 +0100 From: Daniel Fischer [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] Weighted average To: Michael Snoyman [EMAIL PROTECTED], beginners@haskell.org Message-ID: [EMAIL
Beginners Digest, Vol 5, Issue 11
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. help ([EMAIL PROTECTED]) 2. Re: Type polymorphism with size (Brent Yorgey) 3. Re: Type polymorphism with size (David Frey) -- Message: 1 Date: Tue, 18 Nov 2008 16:20:47 -0600 From: [EMAIL PROTECTED] Subject: [Haskell-beginners] help To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=ISO-8859-1 On Tue, 18 Nov 2008 17:12:57 -0500 (EST), [EMAIL PROTECTED] said: Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Profiling haskell code (Brent Yorgey) 2. Parsing arithmentic expressions (Glurk) 3. Re: Parsing arithmentic expressions (Bernie Pope) 4. RE: Profiling haskell code (Sayali Kulkarni) 5. Re: Profiling haskell code (Brent Yorgey) 6. Type polymorphism with size (Michael Snoyman) 7. Re: Type polymorphism with size (Brent Yorgey) 8. Re: Type polymorphism with size (Michael Snoyman) -- Message: 1 Date: Fri, 14 Nov 2008 15:53:34 -0500 From: Brent Yorgey [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] Profiling haskell code To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii quicksort [ ] = [ ] quicksort (x : xs) = quicksort larger ++ [x ] ++ quicksort smaller where smaller = [a | a - xs, a = x ] larger = [b | b - xs, b x ] When I compile the code with the following command : $ ghc --make Project.hs -prof -auto-all Then I tested it with the following command : $ Project +RTS -p It generates the .hi and the .o file but I cannot get the .prof file. Please let me know if any of the steps is missing or where could I check my profiling info. Hi Sayali, Is the code shown above *everything* in your Project.hs file? You will also need a main function for it to actually do anything. If there is more to your Project.hs file that you have not shown, could you send the complete version? Do you get any errors? Does Project produce the output that you expect? -Brent -- Message: 2 Date: Sun, 16 Nov 2008 00:15:29 + (UTC) From: Glurk [EMAIL PROTECTED] Subject: [Haskell-beginners] Parsing arithmentic expressions To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii Hi, I'm just trying to learn how to use Parsec and am experimenting with parsing arithmetic expressions. This article gives a good example - http://www.haskell.org/haskellwiki/Parsing_expressions_and_statements However, like most other examples I could find, the grammar for the expression doesn't take operator precedence into account, and allows for expressions of any size by defining expr recursively, eg :- expr ::= var | const | ( expr ) | unop expr | expr duop expr So, you can keep extending the expression by adding another operator and expression. The data to hold the expression is then very easily derived :- data Expr = Var String | Con Bool | Uno Unop Expr | Duo Duop Expr Expr The grammar I want to parse is slightly different in that it allows for operator precendence. Part of the grammar is something like :- expression = SimpleExpression {relation SimpleExpression}. SimpleExpression = [+|-] term {AddOperator term}. So, instead of recursively defining expression, it is made up of multiples occurrences of SimpleExpression joined together with Relation operators. Where I am confused is how I should best represent this stucture in my data. Should I have something like :- data Expr = Expr SimpleExpr [(RelOp, SimpleExpression)] ie, an initial SimpleExpr, followed by a list of operator and SimpleExpression pairs. I haven't seen any example similar to this, so I was wondering if I'm going down the wrong track ? Perhaps another alternative is to modify the grammar somehow ? I
Beginners Digest, Vol 5, Issue 17
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Homework help (was Re: Help in Haskell) (Benjamin L.Russell) 2. Re: Re: Homework help (was Re: Help in Haskell) (Tillmann Rendel) 3. Re: [Haskell] Re: Help : A problem with IO (abdullah abdul Khadir) 4. ANNOUNCE: Haskell Communities and Activities Report (15th ed., November 2008) (Janis Voigtlaender) 5. Wrapping random (Torsten Otto) 6. Re: Wrapping random (Steven Ashley) -- Message: 1 Date: Thu, 27 Nov 2008 18:32:01 +0900 From: Benjamin L.Russell [EMAIL PROTECTED] Subject: [Haskell-beginners] Re: Homework help (was Re: Help in Haskell) To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii Nevertheless, there is such a thing as a consensus, and given the role of this mailing list, it does seem that rewriting the Homework help - HaskellWiki page in a more egalitarian manner may be worth a try. After all, any changes can be immediately reversed, and I can't see any harm in rewriting the page in a more beginner-friendly manner. Therefore, I have taken the liberty of revising the above-mentioned HaskellWiki page in a less elitist manner, which had long been my eventual intent. We'll see what happens. With luck, the new egalitarian tone will stay. -- Benjamin L. Russell On Thu, 27 Nov 2008 16:44:34 +0900, Benjamin L.Russell [EMAIL PROTECTED] wrote: On Wed, 26 Nov 2008 18:18:45 -0500, [EMAIL PROTECTED] wrote: G'day Benjamin. Quoting Benjamin L.Russell [EMAIL PROTECTED]: As such, first, please follow the homework help procedure outlined in Homework help - HaskellWiki (see http://www.haskell.org/haskellwiki/Homework_help) (substitute haskell-beginners or haskell-cafe for haskell-cafe, and just ignore the part about the existence of stupid questions--there is no such thing as a stupid question; however, there are such things as appropriate questions and inappropriate questions, and in order for us to help you appropriately in this context, you need to show us more specifically what you have done and where you are stuck, so that we can provide help that would be appropriate in this context). It's a wiki. If the wording is bad, fix it! Actually, initially I had to fight the urge not to rewrite it in a less elitist manner, in order to avoid the possibility of offending the original author. In fact, I had been thinking about changing that page since about December of 2007, when I think I first saw it, but had hesitated out of a concern that doing so would have gone against the intent of the original author of that page. On a related issue, I had previously encountered a number of participants on Haskell-Cafe who had reacted negatively against what they apparently thought were stupid questions: One of them even asked (in private e-mail) that a participant not pollute Haskell-Cafe by asking about whether screen resolution was important in determining the precision of an algorithm to compute prime numbers by picking points randomly from a square. I refrained from changing the page because of the possibility that the original author may have been an elitist, who could have changed it back immediately. Part of my original purpose in suggesting the creation of Haskell-Beginners was to create a more non-elitist, beginner-friendly atmosphere. More specifically, since HaskellWiki is also visible to participants on Haskell-Cafe, and not just to those on Haskell-Beginners, if I changed the original intent of the sentence by rephrasing the following sentence (see http://www.haskell.org/haskellwiki/Homework_help): Your lecturer/instructor may have told you that there is no such thing as a stupid question. Inside your classroom, that is correct. Outside your classroom, there are smart questions and stupid questions. If you ask a smart question of the Haskell community, you will probably get a helpful answer. If you ask a stupid question, you will probably get an unhelpful answer or, more likely, no answer at all. to the following sentence: Your lecturer/instructor may have told you that there is no such thing as a stupid question. Indeed, that is correct. However, independent of the context, there are appropriate questions and inappropriate questions. If you first attempt to solve a problem with a decent amount of effort, then get stuck, and then ask for a hint from the Haskell community, your question will most likely be viewed as appropriate, and you
Beginners Digest, Vol 5, Issue 19
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Wrapping random (Andrew Sackville-West) 2. Installing Gtk2hs (Colin Paul Adams) 3. Re: Re: Homework help (was Re: Help in Haskell) ([EMAIL PROTECTED]) 4. In-place lazy I/O (Alexander Dunlap) 5. Re: Installing Gtk2hs (Andy Stewart) 6. Re: Re: Installing Gtk2hs (Colin Paul Adams) 7. Re: In-place lazy I/O (Magnus Therning) 8. Re: Re: Installing Gtk2hs (Colin Paul Adams) 9. Re: Re: Installing Gtk2hs (Colin Paul Adams) -- Message: 1 Date: Sat, 29 Nov 2008 09:02:23 -0800 From: Andrew Sackville-West [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] Wrapping random To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii On Fri, Nov 28, 2008 at 10:53:32PM +0100, Torsten Otto wrote: Hi all, I teach a high school class in Computer Science. The current programming goal is to implement chat-bots, and we're using Haskell of course. Now one of my students had the seemingly easy idea of having the bot answer with a random sentence if it doesn't have good answer. Perhaps instead of using a random number, you could simulate randomness with some other technique. For example, if there is no good response in a particular situation, you could hash the input and map it to some predetermined responses. This would keep you in the IO monad (I think. I'm a total rookie at this). You could then useit as a vehicle to teach some other stuff such as the meaning of random in a computer environment (vs true randomness) and concepts of hashing (even looking into collisions in a simple way because the students will see that different situations reliably give rise to the same outout). .02 A -- next part -- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: Digital signature Url : http://www.haskell.org/pipermail/beginners/attachments/20081129/21f097d8/attachment-0001.bin -- Message: 2 Date: Sat, 29 Nov 2008 21:39:46 + From: Colin Paul Adams [EMAIL PROTECTED] Subject: [Haskell-beginners] Installing Gtk2hs To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii The install instructions seem very straight-forward, but they are not working for me. I did: ./configure --enable-docs --disable-deprecated make su -c'make install' but the demos won't compile (they can't find the libraries). checking the stderr from make shows: ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: mtl make: *** Deleting file `package.conf.inplace' package.conf.inplace: openBinaryFile: does not exist (No such file or directory) package.conf.inplace: openBinaryFile: does not exist (No such file or directory) ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: base ghc-pkg: Unversioned dependencies found: mtl make[1]: *** Deleting file `package.conf.inplace' package.conf.inplace: openBinaryFile: does not exist (No such file or directory) package.conf.inplace: openBinaryFile: does not exist (No such file or directory) on the commandline: Warning: -fffi is deprecated: use -XForeignFunctionInterface or pragma {-# LANGUAGE ForeignFunctionInterface#-} instead package.conf.inplace: openBinaryFile: does not exist (No such file or directory) make[1]: *** [glib/System/Glib.o] Error 1 make: *** [all] Error 2 My environment is Fedora 10 (64-bit). Ghc 6.10.1. Any suggestions? -- Colin Adams Preston Lancashire -- Message: 3 Date: Sat, 29 Nov 2008 18:25:59 -0500 From: [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] Re: Homework help (was Re: Help in Haskell) To: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=ISO-8859-1; DelSp=Yes; format=flowed G'day all. Quoting Benjamin L.Russell [EMAIL PROTECTED]:
Beginners Digest, Vol 6, Issue 1
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: [Haskell-cafe] ANNOUNCE: Haskell Communities and Activities Report (15th ed., November 2008) (Don Stewart) 2. Re: Re: Installing Gtk2hs (Duncan Coutts) 3. Re: Re: Installing Gtk2hs (Duncan Coutts) 4. Re: Memoization (Apfelmus, Heinrich) 5. Re: ANNOUNCE: Haskell Communities and Activities Report (15th ed., November 2008) (Benjamin L.Russell) 6. What causes loop? (Martin Hofmann) 7. Special session on Haskell language (John Edward) -- Message: 1 Date: Fri, 28 Nov 2008 16:15:30 -0800 From: Don Stewart [EMAIL PROTECTED] Subject: [Haskell-beginners] Re: [Haskell-cafe] ANNOUNCE: Haskell Communities and Activities Report (15th ed., November 2008) To: Janis Voigtlaender [EMAIL PROTECTED] Cc: [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], beginners@haskell.org, [EMAIL PROTECTED], [EMAIL PROTECTED] Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=us-ascii Good work! It is always interesting to see the secret Haskell projects that only get announced via the HCAR. Things not on haskell@ or on hackage. For example, this under-the-radar project: http://www.haskell.org/communities/11-2008/html/report.html#sect7.7 7.7 IVU Traffic Technologies AG Rostering Group Haskell to solve constraints on EU bus timetables! In production use! -- Don voigt: On behalf of the many, many contributors, I am pleased to announce that the Haskell Communities and Activities Report (15th edition, November 2008) http://www.haskell.org/communities/ is now available from the Haskell Communities home page in PDF and HTML formats. -- Message: 2 Date: Sun, 30 Nov 2008 22:33:54 + From: Duncan Coutts [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] Re: Installing Gtk2hs To: Colin Paul Adams [EMAIL PROTECTED] Cc: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain On Sun, 2008-11-30 at 09:08 +, Colin Paul Adams wrote: Colin Now make fails with: Colin svgcairo/Graphics/Rendering/Cairo/SVG.chs:201:2: Couldn't Colin match expected type `()' against inferred type `CInt' Colin Expected type: Render () Inferred type: Render CInt In the So I tried changing Render () to Render CInt in four places in SVG.chs. Aye, the cairo C library changed it's API from 1.6 to 1.8. It added an int return type to several functions that previously returned void. Now it installs OK with 6.8.3, and all the demos run. I'd have a go at getting it to work with 6.10.1 if I knew what to do. It appears the library structure has changed incompatibly (and ghc didn't even change its version number - that's pretty bad). The version of ghc did change of course, 6.8 - 6.10, but perhaps you mean the versions of the libraries? They changed also, to reflect the API changes. Is there a document anywhere that details the structure changes? Yes, the ghc-6.10 release notes. Duncan -- Message: 3 Date: Sun, 30 Nov 2008 22:43:45 + From: Duncan Coutts [EMAIL PROTECTED] Subject: Re: [Haskell-beginners] Re: Installing Gtk2hs To: Colin Paul Adams [EMAIL PROTECTED] Cc: beginners@haskell.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain On Sun, 2008-11-30 at 09:24 +, Colin Paul Adams wrote: Colin == Colin Paul Adams [EMAIL PROTECTED] writes: Colin Now it installs OK with 6.8.3, and all the demos run. Well, not quite all: mozembed fails to compile with: TestEmbedMoz.hs:5:7: Could not find module `Graphics.UI.Gtk.MozEmbed': Use -v to see a list of the files searched for. make: *** [testembedmoz] Error 1 This almost certainly is because you didn't build the mozembed component of gtk2hs. The ./configure script lists all the bits that it's going to build. By default if the corresponding C devel package is not available then the binding will not be built. If you really want to build it then use ./configure --enable-firefox or --enable-xulrunner and it will stop and report exactly what bits it needed but could not find. And the svgviewer programs fail at runtime with: svgviewer: user error (Pattern match failure in do expression at SvgViewer.hs:11:2-9) That's kind of by design, it's a simple demo program that does no error checking on the command line arguments. See that line in the source code:
Beginners Digest, Vol 6, Issue 5
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: A type level programming question (Justin Bailey) 2. Problems with one of my first examples (Jeff C. Britton) 3. Re: Problems with one of my first examples (Michael Snoyman) 4. Re: A type level programming question (Levi Stephen) 5. RE: Problems with one of my first examples (Jeff C. Britton) 6. Re: Problems with one of my first examples (Daniel Fischer) -- Message: 1 Date: Mon, 15 Dec 2008 12:03:55 -0800 From: Justin Bailey jgbai...@gmail.com Subject: Re: [Haskell-beginners] A type level programming question To: Levi Stephen levi.step...@gmail.com Cc: beginners@haskell.org Message-ID: a45dff840812151203x2b61a86ck8b6c7c89d9ea4...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 On Sun, Dec 14, 2008 at 3:11 PM, Levi Stephen levi.step...@gmail.com wrote: (!) :: (Pos s, Nat i, i :: s) = FSVec s a - i - a I was wondering if it was possible to write a function of type: elementAt :: FSVec s a - Int - a that called the above function, throwing an error if the index was out of bounds. e.g., Why would you want to write that function? From the signature on (!), it looks like any out of bounds errors should occur at compile time. I'd say the library is trying to make it so you don't have to write that function. That said, I'd try removing the type signature from elementAt and see what your compiler infers for you. You'll also have to find a way to relate idx to v. Unless length v returns a Nat, the comparison you have won't do it. Justin -- Message: 2 Date: Mon, 15 Dec 2008 12:17:33 -0800 From: Jeff C. Britton j...@iteris.com Subject: [Haskell-beginners] Problems with one of my first examples To: beginners@haskell.org Message-ID: 10776152c3da8244baa5d5b10853fe99044e7...@bulldog.iteris.com Content-Type: text/plain; charset=iso-8859-1 Hello, I have started reading Yet Another Haskell Tutorial by Hal Daum´e III which can be found here http://www.cs.utah.edu/~hal/docs/daume02yaht.pdf One of the early examples in section 3.8 pg. 35 is this askForWords = do putStrLn Please enter a word: word - getLine if word == then return [] else do rest - askForWords return (word : rest) I want to print the returned list and everything I try fails. I have tried the following: printList l = if length l = 1 then do putStrLn (head l) printList (tail l) else putStrLn() f = printList askForWords and I get Expression : printList askForWords *** Term : askForWords *** Type : IO [[Char]] *** Does not match : [[Char]] * The exercise right below this asks for a very slight modification to read numbers instead. However, I am confused about how to convert strings to numbers. If I type in the hugs interactive console read 5 + 3 -- 8 -- ok perfect However read 5 gives ERROR - Unresolved overloading *** Type : Read a = a *** Expression : read 5 Yet page 33 of the tutorial has the following code: doGuessing num = do putStrLn Enter your guess: guess - getLine let guessNum = read guess -- ok in let stmt, but not at repl prompt? Anyway I take the info that has been presented and create this function: askForNumbers = do hSetBuffering stdin LineBuffering putStrLn Give me a number (or 0 to stop) numStr - getLine let num = read numStr if num == 0 then return [] else do rest - askForNumbers return (num : rest) However, when I try to use it, like say map sqrt askForNumbers ERROR - Type error in application *** Expression : map sqrt askForNumbers *** Term : askForNumbers *** Type : IO [Integer] *** Does not match : [a] * Is there a way to write printList to handle Strings or numbers? Or should I write printList (map show askForNumbers) Thanks, Jeff -- Message: 3 Date: Mon, 15 Dec 2008 12:48:16 -0800 From: Michael Snoyman mich...@snoyman.com Subject: Re: [Haskell-beginners] Problems with one of my first examples To: Jeff C. Britton j...@iteris.com Cc: beginners@haskell.org Message-ID: 29bf512f0812151248p163b3101pb9fe83c63685f...@mail.gmail.com Content-Type: text/plain; charset=utf-8 On Mon, Dec 15, 2008 at 12:17 PM, Jeff C. Britton
Beginners Digest, Vol 6, Issue 11
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. IO Question (Nathan Holden) 2. Re: IO Question (Alexander Dunlap) 3. about the concatenation on a tree (Max cs) 4. Re: about the concatenation on a tree (Thomas Davie) 5. bottom case in proof by induction (ra...@msn.com) 6. Re: about the concatenation on a tree (Thomas Davie) 7. until and Time (Steve Klabnik) -- Message: 1 Date: Tue, 30 Dec 2008 22:41:02 -0500 From: Nathan Holden nathanmhol...@gmail.com Subject: [Haskell-beginners] IO Question To: beginners@haskell.org Message-ID: 305228b20812301941t781efe6ajf51e644de1255...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 I've been playing around with some types, and such, and I can get some basic IO. But the thing that confused me is this: How is it that IO [Char] == [Char] can be True, but IO a == a is a type error? How can you implement eq for a type so that IO (type) == type? -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20081230/338c9178/attachment-0001.htm -- Message: 2 Date: Tue, 30 Dec 2008 20:36:22 -0800 From: Alexander Dunlap alexander.dun...@gmail.com Subject: Re: [Haskell-beginners] IO Question To: Nathan Holden nathanmhol...@gmail.com Cc: beginners@haskell.org Message-ID: 57526e770812302036x573c6ebam11b0c6c1d8aa5...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 On Tue, Dec 30, 2008 at 7:41 PM, Nathan Holden nathanmhol...@gmail.com wrote: I've been playing around with some types, and such, and I can get some basic IO. But the thing that confused me is this: How is it that IO [Char] == [Char] can be True, but IO a == a is a type error? How can you implement eq for a type so that IO (type) == type? The Eq type class is essentially defined as such: class Eq a where (==) :: a - a - Bool I don't know how you are even calling (==) on objects of type IO [Char] and [Char], since the type signature of (==) says that both of its arguments have to have the same type. Could you give more details of what is going on? Alex -- Message: 3 Date: Wed, 31 Dec 2008 15:02:48 + From: Max cs max.cs.2...@googlemail.com Subject: [Haskell-beginners] about the concatenation on a tree To: beginners@haskell.org, haskell-c...@haskell.org Message-ID: 902ff3e80812310702y7b2e4c28g356baffbb8df...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 hi all, not sure if there is someone still working during holiday like me : ) I got a little problem in implementing some operations on tree. suppose we have a tree date type defined: data Tree a = Leaf a | Branch (Tree a) (Tree a) I want to do a concatenation on these tree just like the concat on list. Anyone has idea on it? or there are some existing implementation? Thank you and Happy New Year! regards, Max -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20081231/20794b50/attachment-0001.htm -- Message: 4 Date: Wed, 31 Dec 2008 17:30:30 +0100 From: Thomas Davie tom.da...@gmail.com Subject: Re: [Haskell-beginners] about the concatenation on a tree To: Max cs max.cs.2...@googlemail.com Cc: beginners@haskell.org, haskell-c...@haskell.org Message-ID: a16f5975-3bfb-466e-ba4b-0966c36ff...@gmail.com Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes On 31 Dec 2008, at 16:02, Max cs wrote: hi all, not sure if there is someone still working during holiday like me : ) I got a little problem in implementing some operations on tree. suppose we have a tree date type defined: data Tree a = Leaf a | Branch (Tree a) (Tree a) I want to do a concatenation on these tree just like the concat on list. Anyone has idea on it? or there are some existing implementation? Thank you and Happy New Year! How would you like to concatenate them? Concatonation on lists is easy because there's only one end point to attach the next list to, on a tree though, there are many leaves to attach things to. Here's a few examples though: Attaching to the right most point on the tree (tree data structure modified to store data in branches not leaves here) data Tree a = Leaf | Branch (Tree a) a (Tree a) concatT :: [Tree a] - Tree a concatT = foldr1 appendT appendT :: Tree a - Tree a - Tree
Beginners Digest, Vol 7, Issue 6
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Meaning of variable' (Bas van Dijk) 2. untilM and scanM (Jan Snajder) 3. Type question (Paul Johnston) 4. Re: Type question (Yitzchak Gale) 5. Re: Type question (Brandon S. Allbery KF8NH) 6. Problems inferring instances (dcmorse+hask...@gmail.com) 7. Re: Problems inferring instances (Dave Bayer) 8. Re: Problems inferring instances (Brandon S. Allbery KF8NH) 9. Re: Yet another monad tutorial. (Benjamin L.Russell) -- Message: 1 Date: Mon, 5 Jan 2009 13:42:41 +0100 From: Bas van Dijk v.dijk@gmail.com Subject: Re: [Haskell-beginners] Meaning of variable' To: Beginners@haskell.org Message-ID: f73f66150901050442uff27476y8040ae25e6f8f...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 On Sun, Jan 4, 2009 at 6:55 AM, Brandon S. Allbery KF8NH allb...@ece.cmu.edu wrote: On 2009 Jan 4, at 0:52, Erik de Castro Lopo wrote: function' = . What does the tick mean?? By convention it signals a variant of the function without the tick... The tick is often used to signal a more strict variant of the function without the tick. See foldl and foldl' for example: http://haskell.org/ghc/docs/latest/html/libraries/base/Data-List.html#v:foldl regards, Bas -- Message: 2 Date: Mon, 05 Jan 2009 14:16:11 +0100 From: Jan Snajder jan.snaj...@fer.hr Subject: [Haskell-beginners] untilM and scanM To: beginners@haskell.org Message-ID: 1231161371.5829.74.ca...@arjuna Content-Type: text/plain Hi, is there a reason why there is no monadic version of until in the Haskell libraries? It would be defined as follows: untilM :: (Monad m) = (a - Bool) - (a - m a) - a - m a untilM p f x | p x = return x | otherwise = f x = untilM p f The same applies to scanM, also not part of the libraries: scanM :: (Monad m) = (a - b - m a) - a - [b] - m [a] scanM f q [] = return [q] scanM f q (x:xs) = do q2 - f q x qs - scanM f q2 xs return (q:qs) I often find myself in need for these. To me these seem idiomatic enough to be included in the library. But since they is not, I guess there must be another, more idiomatic way to do this. Thank you, Jan -- Message: 3 Date: Mon, 05 Jan 2009 20:40:56 + From: Paul Johnston paul.a.johns...@manchester.ac.uk Subject: [Haskell-beginners] Type question To: Haskell beginners@haskell.org Message-ID: 49627058.5010...@manchester.ac.uk Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi, I was playing around after getting the new O'Reilly book with lists and their operators! Not sure what the below actually means? Prelude [] : [] [[]] it :: [[a]] (Got :set +t on ) I thought the first argument of ':' must be an element, so is the empty list an element of the same type of the contents of the empty list? Yours confused Paul :-) -- Message: 4 Date: Tue, 6 Jan 2009 00:52:43 +0200 From: Yitzchak Gale g...@sefer.org Subject: Re: [Haskell-beginners] Type question To: Paul Johnston paul.a.johns...@manchester.ac.uk Cc: Haskell beginners@haskell.org Message-ID: 2608b8a80901051452g17100fa9qe8b37919e1ec0...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 Hi Paul, You wrote: Prelude [] : [] [[]] it :: [[a]] I thought the first argument of ':' must be an element, so is the empty list an element of the same type of the contents of the empty list? There is not just one empty list. The symbol [] is actually polymorphic - it can refer to the empty list in [a], for any type a. In particular, a can itself be a list type. So [] : [] is an element of [[a]], the type of list of lists of a, for any type a. Hope this helps, Yitz -- Message: 5 Date: Mon, 5 Jan 2009 17:53:21 -0500 From: Brandon S. Allbery KF8NH allb...@ece.cmu.edu Subject: Re: [Haskell-beginners] Type question To: Paul Johnston paul.a.johns...@manchester.ac.uk Cc: Haskell beginners@haskell.org Message-ID: ed11d725-86ef-4f12-9262-0d8274b84...@ece.cmu.edu Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes On 2009 Jan 5, at 15:40, Paul Johnston wrote: Hi, I was playing around after getting the new O'Reilly book with lists and their operators! Not sure what the below actually means? Prelude [] : [] [[]] it :: [[a]] (Got :set +t on ) I thought the first argument of ':' must be an element, so is the
Beginners Digest, Vol 7, Issue 13
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. gtk2hs, inputAdd and forked process (Johann Giwer) 2. Is complete decoupling and abstraction possible in Haskell? (Tomer Libal) 3. Re: Is complete decoupling and abstraction possible in Haskell? (Tomer Libal) 4. Re: Is complete decoupling and abstraction possible in Haskell? (Tomer Libal) 5. MULTICONF-09 final call for papers (John Edward) -- Message: 1 Date: Thu, 15 Jan 2009 23:26:25 +0100 From: Johann Giwer johanngi...@web.de Subject: [Haskell-beginners] gtk2hs, inputAdd and forked process To: The Haskell-Beginners Mailing List beginners@haskell.org Message-ID: 20090115222622.ga24...@zitrone Content-Type: text/plain; charset=us-ascii Some times ago I wrote a frontend for mpg123 using python and gtk2. Now I'm trying to do the same in haskell, but my attempt failed in a very early stage. I like to start a subprocess and read its output via 'inputAdd'. The (simplified) code looks like this: module Main (Main.main) where import System.IO.UTF8 hiding (putStr, putStrLn, print) import qualified Control.Exception as E import System.Glib.MainLoop import System.Environment import System.Posix.Process import System.Posix.IO import System.Posix.Types import Graphics.UI.Gtk main :: IO () main = do name - getProgName argv - getArgs case argv of [file] - play file _ - putStrLn $ Usage: ++ name ++ MP3 FILE play :: FilePath - IO () play file = do initGUI (r0,w0) - createPipe (r1,w1) - createPipe pid - forkProcess $ do closeFd w0 closeFd r1 dupTo r0 stdInput dupTo w1 stdOutput executeFile mpg123 True [--output, alsa, --remote] Nothing closeFd w1 closeFd r0 window - windowNew onDestroy window mainQuit button - buttonNew set button [ buttonLabel := Play ] onClicked button $ do w - fdToHandle w0 E.handle ( \e - print e ) $ do hPutStrLn w ( L ++ file ) return () set window [ containerChild := button ] widgetShowAll window inputAdd (fromIntegral r1) [ IOIn,IOPri ] priorityHigh ( readData r1 ) mainGUI readData :: Fd - IO Bool readData h = do E.handle ( \e - print e return True ) $ do (s,_) - fdRead h 1 putStr s return False When loading the file in ghci, I get half a second of sound and a couple of status message lines. Compiled with ghc, this program gives absolute no output (So threading seams to be the problem?). In a next step, I wrapped every IO action in the main process in a call of 'forkIO' and used MVars for the file name and descriptors, but that doesn't help. Does anybody have experience with 'inputAdd' and forked processes? Thanks in advance -Johann -- Message: 2 Date: Fri, 16 Jan 2009 13:35:35 +0100 From: Tomer Libal shaoli...@gmail.com Subject: [Haskell-beginners] Is complete decoupling and abstraction possiblein Haskell? To: beginners@haskell.org Message-ID: ac706fd70901160435o35362b2fp4beee48c8193a...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 Hi, I must add that although in general Theorem provers are very performance oriented, we are not interested in performance in our prover as it is used mainly for testing different refinements and extensions. Therefore, we consider haskell as well (as c++). Also, is there a big reference project, implemented in Haskell, that exhibits some of the OO concepts like decoupling, modulation and abstraction? I understand functional programming has other core values like ease of programming and easy validation of correctness but is it also suitable for large structured projects worked on by many programmers (using decoupling for example)? I have read the previous thread about Monads with great interest. The abstration ideas contained in Wadler's papers gave me hope that there is a way to do a full decoupling and abstraction in Haskell, but I have no idea how. I am interested in building a completely generic resolution theorem prover that all of its parts can be implemented separately. In fact, we already have this prover programmed in c++ but I would be glad if I can reprogram it in Haskell for further extensions of the different parts. The idea of the resolution prover is to get a set of clauses in clasual logic and to try and refute them by using resolution. Some of
Beginners Digest, Vol 7, Issue 21
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Calculating Time Complexity (Adrian Neumann) 2. deleteM :: (Ord a) = a - Maybe (Set a) - Maybe (Set a) (Martin Hofmann) 3. Re: deleteM :: (Ord a) = a - Maybe (Set a) - Maybe (Set a) (Heinrich Apfelmus) 4. Re: Calculating Time Complexity (Brent Yorgey) 5. Follow up to reference request (Alan Cameron) 6. Re: Follow up to reference request (Andrew Wagner) 7. Re: Follow up to reference request (David Frey) 8. Function Type Confusion .. (Tom Poliquin) 9. Re: Function Type Confusion .. (Yitzchak Gale) -- Message: 1 Date: Mon, 26 Jan 2009 08:31:48 +0100 From: Adrian Neumann aneum...@inf.fu-berlin.de Subject: Re: [Haskell-beginners] Calculating Time Complexity To: beginners@haskell.org Message-ID: 643bc7f7-e42e-492f-ab4d-fec7fd35c...@inf.fu-berlin.de Content-Type: text/plain; charset=us-ascii With iterative algorithms like the one you posted it's usually reduced to count the loops. Here we have two nested for-loops, each going from 1 to n. In each loop we do some constant amount of work, so we get (c1*n)*(c2*n) = (c1*c2)*n^2 - Theta(n^2). With recursion it's usually a bit more complicated, as you have to find a closed form. There are however nice lemmata you can use, like the http://en.wikipedia.org/wiki/Master_theorem Regards, Adrian Am 26.01.2009 um 01:04 schrieb Matthew J. Williams: Dear all, In general terms, how would one calculate the time complexity of a given algorithm? Feel free to make use of my pseudo code in your answer: /* input: 2-D array A of size n by n output: a number max */ Max := 0 For i := 1 to n sum := 0 For j := 1 to n sum := sum + A[i][j] End for If sum max then max := sum End for Output max Sincerely Matthew J. Williams ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- next part -- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 194 bytes Desc: Signierter Teil der Nachricht Url : http://www.haskell.org/pipermail/beginners/attachments/20090126/c4a806e2/PGP-0001.bin -- Message: 2 Date: Mon, 26 Jan 2009 10:33:36 +0100 From: Martin Hofmann martin.hofm...@uni-bamberg.de Subject: [Haskell-beginners] deleteM :: (Ord a) = a - Maybe (Set a) - Maybe (Set a) To: beginners@haskell.org Message-ID: 1232962416.6142.14.ca...@ios.cogsys.wiai.uni-bamberg.de Content-Type: text/plain I often come across the problem to insert into a collection which might not exist yet, or delete from it and want the collection to be deleted if it is empty afterwards. I always end up with these two functions: deleteM :: (Ord a) = a - Maybe (Set a) - Maybe (Set a) deleteM e s = liftM (S.delete e) s = \s' - if S.null s' then return s' else Nothing insertM :: (Ord a) = a - Maybe (Set a) - Maybe (Set a) insertM e s = case s of (Just s') - return $ S.insert e s' Nothing - return $ S.insert S.empty Is there a way to express each in a (polymorphic) point-free one-liner? If not, why isn't there such a function for the standard collection, because IMHO this is what you need when using 'alter'. Thanks, Martin -- Message: 3 Date: Mon, 26 Jan 2009 11:22:51 +0100 From: Heinrich Apfelmus apfel...@quantentunnel.de Subject: [Haskell-beginners] Re: deleteM :: (Ord a) = a - Maybe (Set a) - Maybe (Set a) To: beginners@haskell.org Message-ID: glk2sj$9o...@ger.gmane.org Content-Type: text/plain; charset=ISO-8859-15 Martin Hofmann wrote: I often come across the problem to insert into a collection which might not exist yet, or delete from it and want the collection to be deleted if it is empty afterwards. I always end up with these two functions: deleteM :: (Ord a) = a - Maybe (Set a) - Maybe (Set a) deleteM e s = liftM (S.delete e) s = \s' - if S.null s' then return s' else Nothing insertM :: (Ord a) = a - Maybe (Set a) - Maybe (Set a) insertM e s = case s
Beginners Digest, Vol 7, Issue 24
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Help! Trapped in the IO Monad! (Erik de Castro Lopo) 2. Monads... (Cory Knapp) 3. Re: Help! Trapped in the IO Monad! (Alexander Dunlap) 4. Re: Monads... (Erik de Castro Lopo) 5. Re: Help! Trapped in the IO Monad! (Erik de Castro Lopo) 6. Re: Monads... (nanothief) 7. Re: Help! Trapped in the IO Monad! (Erik de Castro Lopo) 8. Re: Monads... (Rafael Gustavo da Cunha Pereira Pinto) -- Message: 1 Date: Thu, 29 Jan 2009 13:14:55 +1100 From: Erik de Castro Lopo mle...@mega-nerd.com Subject: Re: [Haskell-beginners] Help! Trapped in the IO Monad! To: beginners@haskell.org Message-ID: 20090129131455.d80035df.mle...@mega-nerd.com Content-Type: text/plain; charset=US-ASCII Alexander Dunlap wrote: It seems like foldM ought to do what you want. Could you post some more details please? This is a function that I have working in Ocaml which is a little more lenient about IO :-). This is what I have but won't compile: fileNames :: ([FilePath] - FilePath - FilePath - [FilePath]) - [FilePath] - FilePath - IO [FilePath] fileNames builder builder_accum topdir = do names - getDirectoryContents topdir let properNames = filter (`notElem` [., ..]) names (dirs, files) - splitDirFile properNames let accum - foldl' (\ acc f - builder acc topdir f) builder_accum files return $ foldM (\ acc d - fileNames builder accum (topdir / d)) accum dirs I get following error on the foldM: Couldn't match expected type `[FilePath]' against inferred type `IO [FilePath]' Expected type: IO [FilePath] Inferred type: IO (IO [FilePath]) Thinking about it some more, I can see the problem; accum is an IO [FilePath] and my builder function requires a [FilePath]. Once I get the function working I would like to generalize it to: fileNames :: (a - FilePath - FilePath - a) - a - FilePath - IO a Cheers, Erik -- - Erik de Castro Lopo - Re graphics: A picture is worth 10K words - but only those to describe the picture. Hardly any sets of 10K words can be adequately described with pictures. -- Alan Perlis -- Message: 2 Date: Wed, 28 Jan 2009 20:44:30 -0600 From: Cory Knapp thestoneta...@gmail.com Subject: [Haskell-beginners] Monads... To: Beginners@haskell.org Message-ID: 4981180e.5010...@gmail.com Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hello, so, I'm having a simple problem with monads: I have no idea how to actually use them. I understand the category theory (or, at least well enough to be able to explain what is a monad); I understand the way to declare something as a monad instance, but I just don't get how to program with them. Can anyone provide me with, or direct me towards, some simple monads and some ways of using (for example) the monadic properties of lists? Thanks, Cory -- Message: 3 Date: Wed, 28 Jan 2009 18:55:09 -0800 From: Alexander Dunlap alexander.dun...@gmail.com Subject: Re: [Haskell-beginners] Help! Trapped in the IO Monad! To: beginners@haskell.org Message-ID: 57526e770901281855yb4e1540qcf1d69f162aed...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jan 28, 2009 at 6:14 PM, Erik de Castro Lopo mle...@mega-nerd.com wrote: Alexander Dunlap wrote: It seems like foldM ought to do what you want. Could you post some more details please? This is a function that I have working in Ocaml which is a little more lenient about IO :-). This is what I have but won't compile: fileNames :: ([FilePath] - FilePath - FilePath - [FilePath]) - [FilePath] - FilePath - IO [FilePath] fileNames builder builder_accum topdir = do names - getDirectoryContents topdir let properNames = filter (`notElem` [., ..]) names (dirs, files) - splitDirFile properNames let accum - foldl' (\ acc f - builder acc topdir f) builder_accum files return $ foldM (\ acc d - fileNames builder accum (topdir / d)) accum dirs I get following error on the foldM: Couldn't match expected type `[FilePath]' against inferred type `IO [FilePath]' Expected type: IO [FilePath] Inferred type: IO (IO [FilePath]) Thinking about it some more, I
Beginners Digest, Vol 7, Issue 26
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re : Re: [Haskell-beginners] Compile type Error (emmanuel.delaborde) 2. Re: Compile type Error (Daniel Fischer) 3. Re: Compile type Error (Daniel Fischer) 4. Understanding cached fibonnacci function (Patrick LeBoutillier) 5. Re: Understanding cached fibonnacci function (Thomas Davie) 6. Re: Understanding cached fibonnacci function (Daniel Fischer) -- Message: 1 Date: Thu, 29 Jan 2009 16:28:10 + From: emmanuel.delaborde emmanuel.delabo...@cimex.com Subject: Re : Re: [Haskell-beginners] Compile type Error To: beginners@haskell.org Message-ID: 30bf5c42-a6df-4352-bf1c-9abc0bfe5...@cimex.com Content-Type: text/plain; charset=us-ascii On 29 Jan 2009, at 16:10, beginners-requ...@haskell.org wrote: Content-Type: text/plain; charset=iso-8859-1 I didn't compile, but, by the looks of it, I would change import qualified Data.ByteString as BS (readFile) for import qualified Data.ByteString.Lazy as BS (readFile) as it seems sha1 needs a lazy bytestring Thanks ! It compiles now but brings me to my real problem :) If I uncomment this line md5 - md5sum I get the following : -- module Main where import System.Environment (getArgs) import Data.Digest.OpenSSL.MD5 (md5sum) import Data.Digest.Pure.SHA (sha1, showDigest) import qualified Data.ByteString.Lazy as BS (readFile) -- sha1 :: ByteString - Digest -- readFile :: FilePath - IO ByteString -- md5sum :: ByteString - String -- showDigest :: Digest - String checkHash :: String - String - String - IO () checkHash codec hash file = let f = case codec of md5 - md5sum sha1 - showDigest . sha1 _ - error Codec must be md5 or sha1 ! in BS.readFile file = \fileBS - let fileHash = f fileBS in print (hash == fileHash) main = getArgs = \as - case as of (codec:hash:file:_) - checkHash codec hash file _- usage usage = print checksum codec hash file -- which now fails to compile with this error : checksum.hs:17:22: Couldn't match expected type `Data.ByteString.Internal.ByteString' against inferred type `Data.ByteString.Lazy.Internal.ByteString' In the expression: showDigest . sha1 In a case alternative: sha1 - showDigest . sha1 In the expression: case codec of { md5 - md5sum sha1 - showDigest . sha1 _ - error Codec must be md5 or sha1 ! } How can I both use md5sum and sha1 when one use a lazy ByteString end the other one does not ? Thanks E -- Emmanuel Delaborde Web Technologist Cimex 53-55 Scrutton Street, London UK, EC2A 4PJ T: +44 (0)20 7324 7780 F: +44 (0)20 7324 7781 http://www.cimex.com --- This e-mail (and any attachments) is confidential and may contain personal views which are not the views of Cimex Media Ltd and any affiliated companies, unless specifically stated. It is intended for the use of the individual or group to whom it is addressed. If you have received it in error, please delete it from your system, do not use, copy or disclose the information in any way nor act in reliance on it and please notify postmas...@cimex.com A company registered in England Wales. Company Number 03765711 Registered Office : The Olde Bakehouse, 156 Watling Street East, Towcester, Northants NN12 6DB This email was scanned by Postini, the leading provider in Managed Email Security. -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090129/e7355d2e/attachment-0001.htm -- Message: 2 Date: Thu, 29 Jan 2009 17:41:06 +0100 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] Compile type Error To: emmanuel.delaborde emmanuel.delabo...@cimex.com, beginners@haskell.org Message-ID: 200901291741.07042.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-1 Am Donnerstag, 29. Januar 2009 16:25 schrieb emmanuel.delaborde: Hello I have the following snippet : -- module Main where import System.Environment (getArgs) import Data.Digest.OpenSSL.MD5 (md5sum) import Data.Digest.Pure.SHA (sha1, showDigest) import qualified Data.ByteString as BS (readFile) -- sha1 ::
Beginners Digest, Vol 7, Issue 27
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Question about Real World Haskell (David Frey) 2. Re: Question about Real World Haskell (Patrick LeBoutillier) 3. Re: Compile type Error (Chadda? Fouch?) 4. Understanding cached fibonnacci function (Patrick LeBoutillier) 5. Re: Understanding cached fibonnacci function (Rafael Gustavo da Cunha Pereira Pinto) 6. Re: Understanding cached fibonnacci function (Ertugrul Soeylemez) 7. Re: Re: Understanding cached fibonnacci function (Daniel Fischer) 8. Re: Re: Understanding cached fibonnacci function (Patrick LeBoutillier) 9. Re: Re: Understanding cached fibonnacci function (Thomas Davie) -- Message: 1 Date: Thu, 29 Jan 2009 15:27:37 -0800 From: David Frey dpf...@shaw.ca Subject: Re: [Haskell-beginners] Question about Real World Haskell To: alan.came...@iname.com Cc: beginners@haskell.org Message-ID: dcc70e48121ccb11ef99f8161b698...@localhost Content-Type: text/plain; charset=UTF-8 On Thu, 29 Jan 2009 15:21:24 +, Alan Cameron alan.came...@iname.com wrote: In Chapter 3 of Real World Haskell it is not clear to me how to get the myInfo into the ghci system there appears to be two definitions for ch03/BookStore.hs can anyone help? Alan Cameron I assume you are referring to this: -- file: ch03/BookStore.hs data BookInfo = Book Int String [String] deriving show ... Book text here ... -- file: ch03/BookStore.hs data MagazineInfo = Magazine Int String [String] deriving show ... More book text here ... -- file: ch03/BookStore.hs myInfo = Book 9870135072455 Algebra of Programming [Richard Bird, Oege de Moor] When the book mentions a filename, that means that what follows is from that file, but may only be a piece of that file. Save all of these pieces into a file named BookStore.hs and then run ghci BookStore.hs in the same directory as the file. -- Message: 2 Date: Thu, 29 Jan 2009 20:05:51 -0500 From: Patrick LeBoutillier p...@cpan.org Subject: Re: [Haskell-beginners] Question about Real World Haskell To: David Frey dpf...@shaw.ca Cc: beginners@haskell.org, alan.came...@iname.com Message-ID: b217a64f0901291705y1b067408k15585fd8e28d6...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 When the book mentions a filename, that means that what follows is from that file, but may only be a piece of that file. Save all of these pieces into a file named BookStore.hs and then run ghci BookStore.hs in the same directory as the file. You can find the entire source code from the book here: http://examples.oreilly.com/9780596514983/rwh-examples2.zip Patrick -- = Patrick LeBoutillier Rosemère, Québec, Canada -- Message: 3 Date: Fri, 30 Jan 2009 06:14:45 +0100 From: Chadda? Fouch? chaddai.fou...@gmail.com Subject: Re: [Haskell-beginners] Compile type Error To: Daniel Fischer daniel.is.fisc...@web.de Cc: beginners@haskell.org, emmanuel.delaborde emmanuel.delabo...@cimex.com Message-ID: e9350eaf0901292114s31f6abc9l708e51b723b79...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Thu, Jan 29, 2009 at 7:33 PM, Daniel Fischer daniel.is.fisc...@web.de wrote: Convert lazy to strict ByteStrings before using md5sum Or you could use Data.Digest.Pure.MD5 instead of Data.Digest.OpenSSL.MD5, it takes lazy bytestring too. -- Jedaï -- Message: 4 Date: Thu, 29 Jan 2009 13:18:32 -0500 From: Patrick LeBoutillier patrick.leboutill...@gmail.com Subject: [Haskell-beginners] Understanding cached fibonnacci function To: beginners@haskell.org Message-ID: b217a64f0901291018l19072a67y35bc15f67f309...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 Hi all, I recently stumbled on this example in some wiki: mfib :: Int - Integer mfib = (map fib [0 ..] !!) where fib 0 = 0 fib 1 = 1 fib n = mfib (n-2) + mfib (n-1) I don't understand how the results get cached. When mfib is recursively called, doesn't a new (map fib [0 ..] !!) start over again? Or perhaps I'm thinking too imperatively here... Also, if I change the definition to this (adding a on both sides): mfib :: Int - Integer mfib a = (map fib [0 ..] !!) a where fib 0 = 0 fib 1 = 1 fib n = mfib (n-2) + mfib (n-1) the funtion becomes slow again. Why is that? Thanks a lot, Patrick
Beginners Digest, Vol 8, Issue 1
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Understanding cached fibonnacci function (Heinrich Apfelmus) 2. Re: Understanding cached fibonnacci function (Ertugrul Soeylemez) 3. linked lists (Matthew J. Williams) 4. Re: linked lists (David Frey) 5. Circular Linked Lists (Matthew J. Williams) 6. Re: Circular Linked Lists (Erik de Castro Lopo) 7. Re: Circular Linked Lists (Rafael Gustavo da Cunha Pereira Pinto) 8. Re: Circular Linked Lists (Dave Bayer) 9. Re: Circular Linked Lists (Brent Yorgey) 10. Re: Circular Linked Lists (John Hartnup) -- Message: 1 Date: Sat, 31 Jan 2009 11:23:29 +0100 From: Heinrich Apfelmus apfel...@quantentunnel.de Subject: [Haskell-beginners] Re: Understanding cached fibonnacci function To: beginners@haskell.org Message-ID: gm18pl$hc...@ger.gmane.org Content-Type: text/plain; charset=ISO-8859-1 Patrick LeBoutillier wrote: import Data.Function fibs :: Num i = [i] fibs = fix (\r x y - x : r y (x+y)) 0 1 Can someone please explain this one? I can't seem to figure out what 'fix' does (the definition in the documentation is a bit to mathematically inclined for me...). Well, you can just try to replace fix by its definition and see what happens: fix (\r x y - x : r y (x+y)) 0 1 = (let go = (\r x y - x : r y (x+y)) go in go) 0 1 = let go = \x y - x : go y (x+y) in go 0 1 = let go x y = x : go y (x+y) in go 0 1 In other words, fix can define a recursive function. -- http://apfelmus.nfshost.com -- Message: 2 Date: Sat, 31 Jan 2009 16:43:37 +0100 From: Ertugrul Soeylemez e...@ertes.de Subject: [Haskell-beginners] Re: Understanding cached fibonnacci function To: beginners@haskell.org Message-ID: 20090131164337.401c1...@tritium.xx Content-Type: text/plain; charset=UTF-8 Thomas Davie tom.da...@gmail.com wrote: fibs :: Num i = [i] fibs = fix (\r x y - x : r y (x+y)) 0 1 Can someone please explain this one? I can't seem to figure out what 'fix' does (the definition in the documentation is a bit to mathematically inclined for me...). It computes a fixed point for a function â that is a value which when passed to the function gives back the same answer. Some examples: fix id â any value is a fixed point for id, no matter what you give it, it always comes back the same! Beware that 'fix' doesn't simply return an arbitrary fixed point. It gives you _the_ least-defined fixed point, which is bottom for 'fix id'. By the way, it's a very aggressive implementation of bottom. Trying to evaluate 'fix id' may crash your system, unless you set proper memory limits. fix (+ 1) â no values, no matter what you give it, it'll always come out one bigger, so there's no fixed point here It does have a fixed point. Every function has a fixed point. Its fixed point is 1+1+1+1+... It's easy to verify: (+1) (1+1+1+1+...) = 1+1+1+1+... However, the fixed point has the least possible definedness, which means it's bottom. fix (1:) â the infinite list of 1s, if you put a 1 on the front of it, you get back the inifinite list of ones again. Same story here, but (1:) is not strict in its argument, so you get higher definedness than bottom. fix (\r x y - x : r y (x+y)) â Lets try giving this function to itself: (\r x y - x : (y : r (x+y) (y+(x+y, and again... (\r x y - x : (y : ((x+y) : r (y+(x+y)) ((x+y)+y+(x+y... you can see where this is going, if we apply this to 0 and 1, we get 0 : 1 : (0+1) : (1 + (0 + 1)) : ... fibonacci numbers. I find it easier to explain in terms of typed lambda calculus. The problem with it is that you can't express recursion directly in raw lambda notation. The fixed point operator 'fix' gives you the power to do this: fix f = f (fix f) If you pass a lambda to 'fix', then it results in a function, which gets itself as its first argument, so you can express recursion. Say, you would like to write the greatest common divisor algorithm, which is: gcd x 0 = x gcd x y = gcd y (x `mod` y) Now in raw lambda calculus, you can't write equations like above. You can only express functions in terms of their lambdas: (\x y - if y == 0 then x else ...) The problem should be clear: There is no way for the function to call itself. Now the fixed point operator comes into play. It turns the first argument of the function into a recursive reference to itself: fix (\recurse x y - if y
Beginners Digest, Vol 8, Issue 7
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Installing packages (Tymur Porkuian) 2. Re: Installing packages (Krzysztof Skrz?tnicki) 3. cabal-install can't connect (Kirk Martinez) 4. Re: [Haskell-cafe] Just how unsafe is unsafe (Edsko de Vries) 5. Re: cabal-install can't connect (Salvatore Insalaco) 6. Re: Appending to a list (Heinrich Apfelmus) -- Message: 1 Date: Mon, 9 Feb 2009 01:21:18 +0200 From: Tymur Porkuian shooshpanch...@gmail.com Subject: Re: [Haskell-beginners] Installing packages To: Krzysztof Skrz?tnicki gte...@gmail.com Cc: beginners@haskell.org Message-ID: 7f22364a0902081521n1cbdfb22t99506d7e3bcf9...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 I'm trying to install wxcore-0.11.0 using Cabal. I've downloaded it from http://hackage.haskell.org/cgi-bin/hackage-scripts/package/wxcore-0.11.0, unpacked and tried to follow instructions from http://haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package, but this is what I'm getting: D:\libraries\wxcore-0.11.0runhaskell Setup configure Setup: sh: runGenProcess: does not exist (No such file or directory) What does this mean? On Windows it usually means that the package has a configure shell script and therefore requires that Cygwin or MSYS be installed. I have installed Cygwin, and still getting the exact same error. Should something else be done after installing it? Are you running cabal install from within Cygwin prompt? No, I'm not running cabal install, I'm running runhaskell Setup configure (as written in http://haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package). cabal is not even on the PATH, actually. Now I launched this command from cygwin, this is what I got: .../cygdrive/d/libraries/wxcore-0.11.0 $ runhaskell.exe Setup configure warning: Unable to find wxWidgets configuration (wx-config). checking system: error: Unable to find the 'wx-config' program: wx-config Maybe you forgot to run 'make install' on wxWidgets? Otherwise, add the install directory of wx-config to your path. Or maybe you are trying to compile with Microsoft Visual C++? If so, you can specify that on the command line: For example: ./configure --with-msc What is wx-config and where can I get it? -- Message: 2 Date: Mon, 9 Feb 2009 00:27:19 +0100 From: Krzysztof Skrz?tnicki gte...@gmail.com Subject: Re: [Haskell-beginners] Installing packages To: shooshpanch...@gmail.com Cc: beginners@haskell.org Message-ID: 220e47b40902081527m10075796l41854116e5029...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Mon, Feb 9, 2009 at 00:21, Tymur Porkuian shooshpanch...@gmail.com wrote: Are you running cabal install from within Cygwin prompt? No, I'm not running cabal install, I'm running runhaskell Setup configure (as written in http://haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package). cabal is not even on the PATH, actually. Now I launched this command from cygwin, this is what I got: .../cygdrive/d/libraries/wxcore-0.11.0 $ runhaskell.exe Setup configure warning: Unable to find wxWidgets configuration (wx-config). checking system: error: Unable to find the 'wx-config' program: wx-config Maybe you forgot to run 'make install' on wxWidgets? Otherwise, add the install directory of wx-config to your path. Or maybe you are trying to compile with Microsoft Visual C++? If so, you can specify that on the command line: For example: ./configure --with-msc What is wx-config and where can I get it? You need wxWidgets sources: get them at http://www.wxwidgets.org/downloads/#latest_stable . After that you need to install them appropriately, so that wx-config will be in PATH. All best Christopher SkrzÄtnicki -- Message: 3 Date: Fri, 6 Feb 2009 10:25:06 -0800 From: Kirk Martinez kmart...@altera.com Subject: [Haskell-beginners] cabal-install can't connect To: 'beginners@haskell.org' beginners@haskell.org Message-ID: aaa7e9adec517141984ab6a6d594eff143198c4...@sj-itmsg02.altera.priv.altera.com Content-Type: text/plain; charset=us-ascii I'm trying to use cabal-install through the firewall at my work and I am consistently denied: C:\cabal update -v3 Downloading package list from server 'http://hackage.haskell.org/packages/archive' Sending: GET http://hackage.haskell.org/packages/archive/00-index.tar.gz HTTP/1.1 User-Agent:
Beginners Digest, Vol 8, Issue 8
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Recursive Let (Tom Poliquin) 2. Re: Recursive Let (Brandon S. Allbery KF8NH) 3. A Comparison of Haskell and Scheme (Benjamin L.Russell) 4. Re: A Comparison of Haskell and Scheme (Albert Krewinkel) 5. Re: A Comparison of Haskell and Scheme (Benjamin L.Russell) 6. Re: A Comparison of Haskell and Scheme (Benjamin L.Russell) 7. Re: A Comparison of Haskell and Scheme (Felipe Lessa) -- Message: 1 Date: Mon, 9 Feb 2009 17:43:03 -0800 From: Tom Poliquin poliq...@softcomp.com Subject: [Haskell-beginners] Recursive Let To: beginners@haskell.org Message-ID: 200902091743.03601.poliq...@softcomp.com Content-Type: text/plain; charset=us-ascii I'm working on learning arrows. This has led me to ArrowLoop, which then led me to trying to understand the following, tracePlus b = let (c,d) = (d,b:d) in c main = do w - return $ take 10 $ tracePlus 7 print w which yields [7,7,7,7,7,7,7,7,7,7] My confusion two pronged, 1) How let actually 'recurses' 2) How things get started (since d is undefined). I have some vague understanding of both issues but I want to make sure what's *really* going on so I don't base my Haskell learning experience on a house of cards. Help greatly appreciated. My ramblings 1) How does recursion happen? Being an ex-Schemer I recalled that let x = 3 get translated into something like (lambda (x) ... ) 3 So now there's a function involved. It's clear that b:d is (cons b d) another function. So with appropriate plumbing I could see the thing recurses but the Haskell viewpoint eludes me. 2) How do things get started? It seems that Haskell could figure out that 'd' is a list. If an uninitialized (undefined?) list contains [] then things are reasonably straightforward .. tracePlus gets applied to 7 (b:d) then becomes [7] (c,d) then becomes ([],7) Given there's an infinite loop (stream) then 'take' grabs 'c' (an []) and asks for another. Haskell's laziness works for us here. (b:d) then becomes [7,7] (c,d) then becomes (7,[7,7]) ... ... This is all fine. The only thing that subconsciously nags me is that we appear to 'return' each time which would imply that we would leave the closure causing 'd' to be undefined again. I know this isn't true and if I close my eyes, think really hard, and recall how streams are implemented in Scheme (with a value-promise pair; the closure is actually passed around) then I can see how this would all work. Back to the undefined list ... if it's *not* an [] and has something to do with bottom ( _|_ ) then my eyes glaze over and I have to go watch a Woody Allen movie to reset. Sorry for the rambling. I really like Haskell and I have found it very powerful. Any help greatly appreciated. Thanks, Tom -- Message: 2 Date: Mon, 9 Feb 2009 23:42:23 -0500 From: Brandon S. Allbery KF8NH allb...@ece.cmu.edu Subject: Re: [Haskell-beginners] Recursive Let To: Tom Poliquin poliq...@softcomp.com Cc: beginners@haskell.org Message-ID: 6a551b70-66c4-4a16-8451-4e6f5b458...@ece.cmu.edu Content-Type: text/plain; charset=us-ascii On 2009 Feb 9, at 20:43, Tom Poliquin wrote: I'm working on learning arrows. This has led me to ArrowLoop, which then led me to trying to understand the following, tracePlus b = let (c,d) = (d,b:d) in c main = do w - return $ take 10 $ tracePlus 7 print w 1) How does recursion happen? Being an ex-Schemer I recalled that let x = 3 get translated into something like (lambda (x) ... ) 3 So now there's a function involved. It's clear that b:d is (cons b d) another function. So with appropriate plumbing I could see the thing recurses but the Haskell viewpoint eludes me. The trick is that the c and d on both sides of the equal sign are identical. Since this asserts that d = b:d, Haskell repeatedly prepends b to d (lazily, so take 10 halts the recursion). let (c,d) = (d,b:d) in c = d let (c,d) = (b:d,b:b:d) in c = b:d let (c,d) = (b:b:d,b:b:b:d) in c = b:b:d ... As long as something consumes elements from c, that let will continue to expand recursively. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH
Beginners Digest, Vol 8, Issue 16
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Sequential IO processing (Andrew Wagner) 2. Re: Sequential IO processing (Sergey V. Mikhanov) 3. Re: Sequential IO processing (Heinrich Apfelmus) 4. Re: Re: Sequential IO processing (Sergey V. Mikhanov) 5. Re: Re: Sequential IO processing (Felipe Lessa) 6. Counting Fruits (Adolfo Builes) 7. Re: Counting Fruits (Alexander Dunlap) -- Message: 1 Date: Thu, 19 Feb 2009 10:19:35 -0500 From: Andrew Wagner wagner.and...@gmail.com Subject: Re: [Haskell-beginners] Sequential IO processing To: Sergey V. Mikhanov ser...@mikhanov.com Cc: beginners@haskell.org Message-ID: b8a8636e0902190719xf7beb26j215f8a31746fe...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 You did really well here. There's just one small detail that you missed, which is causing the problem: sequenceIO [] = return [] sequenceIO (x : xs) = do result - x return result : sequenceIO xs The problem is indeed here. The type of 'sequenceIO xs' is IO [a], but the type of result is 'a'. You can't cons an 'a' onto an 'IO [a]'. Thus, what you need is something like this: sequenceIO [] = return [] sequenceIO (x : xs) = do result - x xs' - sequenceIO xs -- to take the list out of the IO Monad return result : xs' On Thu, Feb 19, 2009 at 9:56 AM, Sergey V. Mikhanov ser...@mikhanov.comwrote: Hi community, I am making my first steps in Haskell, reading Haskell wikibook and now stuck with one of the excercises, namely this one: Implement a function sequenceIO :: [IO a] - IO [a]. Given a list of actions, this function runs each of the actions in order and returns all their results as a list. This is what I came with: ioOne :: Num a = IO a ioOne = do print guid return guid where guid = 2 ioTwo :: Num a = IO a ioTwo = do print guid return guid where guid = 3 sequenceIO :: Num a = [IO a] - IO [a] sequenceIO [] = return [] sequenceIO (x : xs) = do result - x return result : sequenceIO xs First two functions are there because of the invocation that I've planned: sequenceIO [getGuid, getNextGuid]. However, this could not be compiled (GHC): Couldn't match expected type `[m a]' against inferred type `IO [a]' In the second argument of `(:)', namely `sequenceIO xs' In the expression: return result : sequenceIO xs In the expression: do result - x return result : sequenceIO xs Fine, I thought, something wrong with the type of the 'sequenceIO xs' (becasue I am sure the type of 'result' is fine). So I wrote another program to check what happens to the result of IO action evaluation (namely, which type is assigned): bar :: Num a = IO a bar = do print guid return guid where guid = 2 foo = do result - bar result This could not be compiled either: No instance for (Num (IO b)) arising from a use of `bar' at auxil.hs:8:19-21 Possible fix: add an instance declaration for (Num (IO b)) In a stmt of a 'do' expression: result - bar In the expression: do result - bar result In the definition of `foo': foo = do result - bar result I am a newbie, so I am interpreting this like Haskell could not construct Num from the result of invocation of bar, which is of type IO a. But why do I need this at all? When doing console I/O with 'result - getLine', I do not need to reconstruct String from the result. What am I doing wrong? Where is the failure in reasoning? Thanks, Sergey ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090219/3e166623/attachment-0001.htm -- Message: 2 Date: Thu, 19 Feb 2009 16:27:02 +0100 From: Sergey V. Mikhanov ser...@mikhanov.com Subject: Re: [Haskell-beginners] Sequential IO processing To: beginners beginners@haskell.org Message-ID: b38b3dd10902190727p5eaaf9dbn9c5e04a45c4fe...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 I tried this earlier as well: sequenceIO [] = return [] sequenceIO (x : xs) = do result - x
Beginners Digest, Vol 9, Issue 6
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: let indenting problems (Heinrich Apfelmus) 2. infix and bind pseudonym (Michael Easter) 3. basic threading (Michael Easter) 4. Re: infix and bind pseudonym (Magnus Therning) 5. Re: infix and bind pseudonym (Daniel Fischer) 6. Re: infix and bind pseudonym (Daniel Fischer) 7. Re: basic threading (Thomas Davie) 8. Re: basic threading (Henk-Jan van Tuyl) -- Message: 1 Date: Tue, 03 Mar 2009 12:20:45 +0100 From: Heinrich Apfelmus apfel...@quantentunnel.de Subject: [Haskell-beginners] Re: let indenting problems To: beginners@haskell.org Message-ID: goj3og$ba...@ger.gmane.org Content-Type: text/plain; charset=ISO-8859-1 7stud wrote: Heinrich Apfelmus apfelmus at quantentunnel.de writes: How about import Data.Ord (comparing) mySort = sortBy (comparing length) I just finished chap. 3 of Real World Haskell, which doesn't even imports. It took me hours to figure out how to access sortBy. The book hasn't introduced comparing, yet. It's a handy little function for exactly this sort of thing. It's defined as comparing p x y = compare (p x) (p y) See also http://haskell.org/hoogle/?q=comparing or at least mySort = sortBy myCompare where myCompare x y = compare (length x) (length y) Very nice. The book mentioned the compare function in chap. 2. I have a question about that code: how come you don't have to specify a parameter for mySort, for example: mySort xs = ... And doesn't sortBy require two arguments? sortBy :: (a - a - Ordering) - [a] - [a] (1) (2) How come you can write it with only one argument? You can supply arguments one at a time, this is called currying. In other words, the expression sortBy myCompare is created by supplying one argument to sortBy and thus has one argument remaining. More specifically, it has the type sortBy myCompare :: [[a]] - [[a]] Furthermore, we can simply set mySort = sortBy myCompare and the left hand side will be a function with one argument just like the right hand side is. Finally, I'm wondering if anyone can explain why my let examples failed? Your use of let in conjunction with where was not syntactically correct. While both are used for declaring new things, let is an expression while where is a declaration, these two don't mix. In particular, let must always have the form let x = ... y = ... ... in expr while where is used like this foo x y | ... = expr1 | ... = expr2 where a = ... b = ... ... Construction like let ... in where ... let ... in | ... do not exist, there is no expression after the in . I suggest consulting a syntax reference for Haskell or using where only for the time being. Regards, apfelmus -- http://apfelmus.nfshost.com -- Message: 2 Date: Wed, 4 Mar 2009 06:25:06 -0600 From: Michael Easter codeto...@gmail.com Subject: [Haskell-beginners] infix and bind pseudonym To: beginners@haskell.org Message-ID: 1d393c9d0903040425y77cf2c65n2ea9f5ae4a5fb...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 Folks, I have a simple type called Beverage and an example that allows me to construct Maybe Beverage types. Here are some type signatures for example functions: request :: String - Maybe Beverage addMalt :: Beverage - Maybe Beverage I have defined a chain function like so: chain :: (Maybe a) - (a - Maybe b) - (Maybe b) chain = (=) I can do this: (chain (request beer) addMalt) and request beer `chain` addMalt I think I understand why, as I use the back-ticks for infix. However, I don't have to do that for the true bind function, (=) request beer = addMalt I would like to use chain in this way -- that is without back-ticks. I'm not sure how... Is there something I'm missing? thanks Mike ps. Thanks to everyone for the great discussion on IO (re: previous question) -- -- Michael Easter http://codetojoy.blogspot.com: Putting the thrill back in blog http://youtube.com/ocitv - Fun people doing serious software engineering -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090304/9f5050a2/attachment-0001.htm -- Message: 3 Date: Wed, 4 Mar 2009 06:33:37 -0600 From:
Beginners Digest, Vol 9, Issue 11
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: folds -- help! (7stud) 2. Simple data summarization (Andy Elvey) 3. Re: installing cabal with 6.10 - ubuntu (Christian Maeder) 4. Re: Re: folds -- help! (Kurt Hutchinson) 5. Re: installing cabal with 6.10 - ubuntu (B) 6. Re: Simple data summarization (Roland Zumkeller) 7. Re: Simple data summarization (Thomas Davie) 8. Re: Simple data summarization (Patrick LeBoutillier) -- Message: 1 Date: Tue, 10 Mar 2009 08:01:19 + (UTC) From: 7stud bbxx789_0...@yahoo.com Subject: [Haskell-beginners] Re: folds -- help! To: beginners@haskell.org Message-ID: loom.20090310t075932-...@post.gmane.org Content-Type: text/plain; charset=us-ascii Peter Verswyvelen bugfact at gmail.com writes: Does this help? Sorry, I'm only on chapter 4 of RWH, and I don't understand that notation. -- Message: 2 Date: Tue, 10 Mar 2009 21:33:00 +1300 From: Andy Elvey andy.el...@paradise.net.nz Subject: [Haskell-beginners] Simple data summarization To: beginners@haskell.org Message-ID: 49b625bc.7060...@paradise.net.nz Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi all - In the process of learning Haskell I'm wanting to do some simple data summarization. ( Btw, I'm looking at putting any submitted code for this in the cookbook section of the Haskell wiki. Imo it would be very useful there as a next step up from just reading in a file and printing it out. ) This would involve reading in a delimited file like this - ( just a contrived example of how many books some people own ) - Name,Gender,Age,Ethnicity,Books Mary,F,14,NZ European, 11 Brian,M,13,NZ European, 6 Josh,M,12,NZ European, 14 Regan,M,14,NZ Maori, 9 Helen,F,15,NZ Maori, 17 Anna,F,14,NZ European, 16 Jess,F,14,NZ Maori, 21 and doing some operations on it. As you can see, the file has column headings - I prefer to be able to manipulate data with headings (as it is what I do a lot of at work, using another programming language). I've tried to break the problem down into small parts as follows. a) Read the file into a list of pairs. The first element of the pair would be the column heading. The second will be a list containing the data. For example, (Name, [Mary, Brian, Josh, Regan, . ] ) b) Select a numeric variable to summarise ( Books in this example) c) Do a fold to summarize the variable. I think a left-fold would be the one to use here, but I may be wrong After looking through previous postings on this list, I found some code which is somewhat similar to what I'm after (although the data it was crunching is very different). This is what I've come up with so far - summarize [] = [] summarize ls = let byvariable = head ls numeric_variable = last ls sum = foldl (+) 0 $ numeric_variable in (byvariable, sum) : sum ls main = interact (unlines . map show . summarize . lines) I think this might be a useful start, but I still need to read the data into a list of pairs as mentioned, and I'm unsure as to how to do that. Many thanks in advance for any help received. As mentioned, I'm sure that examples like this could be very useful to other beginners, so I'm keen to make sure that any help given is made maximum use of (by putting any code on the Haskell wiki). - Andy -- Message: 3 Date: Tue, 10 Mar 2009 09:49:39 +0100 From: Christian Maeder christian.mae...@dfki.de Subject: [Haskell-beginners] Re: installing cabal with 6.10 - ubuntu To: B bburde...@comcast.net Cc: beginners@haskell.org Message-ID: 49b629a3.5070...@dfki.de Content-Type: text/plain; charset=ISO-8859-1 B wrote: I found some directions online that said that compiling from source might be a good way to go. I downloaded and compiled ghc 6.10.1, installing it locally. Next time include the extra-libraries in your sources, to avoid installing so many packages afterwards. Ok. Now when I go to build network I get this: Could not find module `Data.Generics': it is a member of package base-3.0.3.0, which is hidden According to google, the above message actually indicates that 'syb' is needed, the bug is here: http://hackage.haskell.org/trac/ghc/ticket/2980 - installed syb-0.1.0.0. - still get the same message. At this point I'm stuck! Are you sure you have version 2.2.0.1
Beginners Digest, Vol 9, Issue 12
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Integer factorization (Christian Maeder) 2. Re: folds -- help! (Heinrich Apfelmus) 3. Re: Integer factorization (Heinrich Apfelmus) 4. Re: folds -- help! (7stud) 5. Re: folds -- help! (John Dorsey) 6. Re: Simple data summarization (Andy Elvey) 7. Re: Re: Integer factorization (Francesco Bochicchio) -- Message: 1 Date: Tue, 10 Mar 2009 18:24:31 +0100 From: Christian Maeder christian.mae...@dfki.de Subject: [Haskell-beginners] Re: Integer factorization To: Sergey V. Mikhanov ser...@mikhanov.com Cc: beginners beginners@haskell.org Message-ID: 49b6a24f.2070...@dfki.de Content-Type: text/plain; charset=ISO-8859-1 On http://www.haskell.org/haskellwiki/Prime_numbers primeFactors should do what you want (although I don't like the the pattern matching on 1) Cheers Christian Sergey V. Mikhanov wrote: Hello, I am solving a problem of finding the largest prime factor of 600851475143 (Project Euler is great for learning new language!), and came with the following solution (it uses the most ineffective approach to finding prime numbers, however is able to factor the above number in fraction of second): factors :: Integer - [Integer] factors n = doFactors n (eratosthenesFilter [1..n]) doFactors n primes | null newPrimes = [] | otherwise = let topPrime = head newPrimes in if topPrime == n then [topPrime] else topPrime : (doFactors (n `quot` topPrime) primes) where newPrimes = snd $ break (\x - (n `rem` x) == 0) primes eratosthenesFilter :: [Integer] - [Integer] eratosthenesFilter [] = [] eratosthenesFilter (num : nums) | num == 1 = eratosthenesFilter nums | otherwise = num : (eratosthenesFilter $ doFilter num nums) where doFilter num nums = filter (\x - x num (x `rem` num) /= 0) nums What would you do different (including stylistic changes)? What are the general comments about efficiency (not of the algorithm, but of the implementation: for example, is it fine to use break at every invocation of doFactors?) and elegance of the solution? Thanks and regards, Sergey -- Message: 2 Date: Tue, 10 Mar 2009 19:31:50 +0100 From: Heinrich Apfelmus apfel...@quantentunnel.de Subject: [Haskell-beginners] Re: folds -- help! To: beginners@haskell.org Message-ID: gp6bkk$r1...@ger.gmane.org Content-Type: text/plain; charset=UTF-8 7stud wrote: This is an example that shows how foldl and foldr work (from RWH p.93-94): foldl (+) 0 (1:2:3:[]) == foldl (+) (0 + 1) (2:3:[]) == foldl (+) ((0 + 1) + 2) (3:[]) == foldl (+) (((0 + 1) + 2) + 3) [] == (((0 + 1) + 2) + 3) foldr (+) 0 (1:2:3:[]) == 1 + foldr (+) 0 (2:3:[]) == 1 + (2 + foldr (+) 0 (3:[]) == 1 + (2 + (3 + foldr (+) 0 [])) == 1 + (2 + (3 + 0)) The book says on p.94: - The difference between foldl and foldr should be clear from looking at where the parentheses and the empty list elements show up. With foldl, the empty list element is on the left, and all the parentheses group to the left. With foldr, the zero value is on the right, and the parentheses group to the right. Huh? With foldl, the only empty list element I see is on the right. A fold like foldr f z is best understood as a function that replaces each (:) with f and each [] with z . See also the diagrams on http://en.wikipedia.org/wiki/Fold_(higher-order_function) From this point of view, z corresponds to the empty list. Initially, it looked to me like they did the same thing, and that the only difference was the way they called step. They are only the same when the operation f is associative, i.e. if it satisfies f x (f y z) = f (f x y) z But then RWH explains that you would never use foldl in practice because it thunks the result, which for large lists can overwhelm the maximum memory alloted for a thunk. But it appears to me the same thunk problem would occur with foldr. So why is foldr used in practice but not foldl? See also http://en.wikibooks.org/wiki/Haskell/Performance_Introduction#Space Regards, apfelmus -- http://apfelmus.nfshost.com -- Message: 3 Date: Tue, 10 Mar 2009 19:50:11 +0100 From: Heinrich Apfelmus apfel...@quantentunnel.de Subject: [Haskell-beginners] Re:
Beginners Digest, Vol 9, Issue 18
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: MD2 Implementation (Rafael Gustavo da Cunha Pereira Pinto) 2. Re: Hudak state emulation discussion - can you give me some idea? (Benjamin L.Russell) 3. Understanding recursion in Haskell. (Caitlin) 4. Re: Understanding recursion in Haskell. (Adrian Neumann) 5. Re: Re: Hudak state emulation discussion - can you give me some idea? (Girish Bhat) -- Message: 1 Date: Tue, 17 Mar 2009 11:15:10 -0300 From: Rafael Gustavo da Cunha Pereira Pinto rafaelgcpp.li...@gmail.com Subject: Re: [Haskell-beginners] MD2 Implementation To: Sean Bartell wingedtachik...@gmail.com Cc: beginners@haskell.org Message-ID: 351ff25e0903170715s6c11ae98pe7892acae1271...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 I am studying your code, and noticed you used a ByteString for your table This is bad, because you are doing a O(n) lookup every time you do a b `xor` table `B.index` fromIntegral t On Mon, Mar 16, 2009 at 00:33, Sean Bartell wingedtachik...@gmail.comwrote: I've just recently started learning Haskell, and I wrote an MD2 implementation. This version is correct, but crashes on large files because of the weak evaluation. What I'm wondering is, what's the sort of thought-process I would go through to find the problem areas and fix it? Also, please post any suggestions you have for this code, for style or whatever :). {-# LANGUAGE BangPatterns #-} module MD2 (md2) where import qualified Data.ByteString as B import Data.Bits (xor) import Data.List (foldl', mapAccumL) import Data.Word (Word8) table = B.pack [0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01, 0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13, 0x62, 0xA7, 0x05, 0xF3, 0xC0, 0xC7, 0x73, 0x8C, 0x98, 0x93, 0x2B, 0xD9, 0xBC, 0x4C, 0x82, 0xCA, 0x1E, 0x9B, 0x57, 0x3C, 0xFD, 0xD4, 0xE0, 0x16, 0x67, 0x42, 0x6F, 0x18, 0x8A, 0x17, 0xE5, 0x12, 0xBE, 0x4E, 0xC4, 0xD6, 0xDA, 0x9E, 0xDE, 0x49, 0xA0, 0xFB, 0xF5, 0x8E, 0xBB, 0x2F, 0xEE, 0x7A, 0xA9, 0x68, 0x79, 0x91, 0x15, 0xB2, 0x07, 0x3F, 0x94, 0xC2, 0x10, 0x89, 0x0B, 0x22, 0x5F, 0x21, 0x80, 0x7F, 0x5D, 0x9A, 0x5A, 0x90, 0x32, 0x27, 0x35, 0x3E, 0xCC, 0xE7, 0xBF, 0xF7, 0x97, 0x03, 0xFF, 0x19, 0x30, 0xB3, 0x48, 0xA5, 0xB5, 0xD1, 0xD7, 0x5E, 0x92, 0x2A, 0xAC, 0x56, 0xAA, 0xC6, 0x4F, 0xB8, 0x38, 0xD2, 0x96, 0xA4, 0x7D, 0xB6, 0x76, 0xFC, 0x6B, 0xE2, 0x9C, 0x74, 0x04, 0xF1, 0x45, 0x9D, 0x70, 0x59, 0x64, 0x71, 0x87, 0x20, 0x86, 0x5B, 0xCF, 0x65, 0xE6, 0x2D, 0xA8, 0x02, 0x1B, 0x60, 0x25, 0xAD, 0xAE, 0xB0, 0xB9, 0xF6, 0x1C, 0x46, 0x61, 0x69, 0x34, 0x40, 0x7E, 0x0F, 0x55, 0x47, 0xA3, 0x23, 0xDD, 0x51, 0xAF, 0x3A, 0xC3, 0x5C, 0xF9, 0xCE, 0xBA, 0xC5, 0xEA, 0x26, 0x2C, 0x53, 0x0D, 0x6E, 0x85, 0x28, 0x84, 0x09, 0xD3, 0xDF, 0xCD, 0xF4, 0x41, 0x81, 0x4D, 0x52, 0x6A, 0xDC, 0x37, 0xC8, 0x6C, 0xC1, 0xAB, 0xFA, 0x24, 0xE1, 0x7B, 0x08, 0x0C, 0xBD, 0xB1, 0x4A, 0x78, 0x88, 0x95, 0x8B, 0xE3, 0x63, 0xE8, 0x6D, 0xE9, 0xCB, 0xD5, 0xFE, 0x3B, 0x00, 0x1D, 0x39, 0xF2, 0xEF, 0xB7, 0x0E, 0x66, 0x58, 0xD0, 0xE4, 0xA6, 0x77, 0x72, 0xF8, 0xEB, 0x75, 0x4B, 0x0A, 0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A, 0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14] -- NOTE: There's a problematic typo in RFC 1319 in section 3.2. It says -- Set C[j] to S[c xor L], but it should be Set C[j] to C[j] xor S[c xor L]. type Block = B.ByteString two x = (x, x) applySnd f (x, y) = (x, f y) zeroBlock = B.replicate 16 0 checksumInitial = (0, zeroBlock) foldlBlocks :: (a - Block - a) - a - B.ByteString - a foldlBlocks f v x | B.null x = v | otherwise = foldlBlocks f v' rest where (block, rest) = B.splitAt 16 x !v' = f v block checksumBlock :: (Word8, Block) - Block - (Word8, Block) checksumBlock (l, cs) bs = applySnd B.pack $ mapAccumL updateL l $ B.zip cs bs where updateL l (c, b) = two $ c `xor` table `B.index` fromIntegral (l `xor` b) doBlock :: Block -
Beginners Digest, Vol 9, Issue 19
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Understanding recursion in Haskell. (the_polymo...@rocketmail.com) 2. Re: Understanding recursion in Haskell. (7stud) 3. Re: Understanding recursion in Haskell. (Sean Lee) 4. Re: Understanding recursion in Haskell. (Thomas Davie) 5. Re: Hudak state emulation discussion - can you give me some idea? (Benjamin L.Russell) 6. How to display a time difference? (Colin Paul Adams) -- Message: 1 Date: Wed, 18 Mar 2009 00:36:57 -0700 (PDT) From: the_polymo...@rocketmail.com Subject: Re: [Haskell-beginners] Understanding recursion in Haskell. To: beginners@haskell.org Message-ID: 390551.23952...@web50807.mail.re2.yahoo.com Content-Type: text/plain; charset=iso-8859-1 Hi Adrian, Thanks for the explanations. Could we perhaps examine one recursive example in detail, i.e., step-by-step, as I'm still confused? Maybe the following program from chapter 2 of http://book.realworldhaskell.org? myDrop n xs = if n = 0 || null xs then xs else myDrop (n - 1) (tail xs) Danke, Caitlin --- On Wed, 3/18/09, Adrian Neumann aneum...@inf.fu-berlin.de wrote: From: Adrian Neumann aneum...@inf.fu-berlin.de Subject: Re: [Haskell-beginners] Understanding recursion in Haskell. To: beginners@haskell.org Date: Wednesday, March 18, 2009, 12:05 AM Am 18.03.2009 um 06:28 schrieb Caitlin: Hi. As a Haskell beginner, I was wondering if someoneone could explain how the following programs function (pardon the pun)? This function takes some type which has an ordering defined, i.e. you can compare its elements to one another maximum' :: (Ord a) = [a] - a it doesn't work for an empty list maximum' [] = error maximum of empty list the maximum of a one element list is the lone element. this is the base case which will be eventually reached by the recursion maximum' [x] = x should the list have more than one element maximum' (x:xs) compare the first element to the maximum of the other elements. if it's greater, it's the maximum | x maxTail = x otherwise the maximum of the other elements is the maximum of the whole list | otherwise = maxTail how to compute the maximum of the other elements? just use this function again. after a while we will only have one element left and reach the base case above. where maxTail = maximum' xs This function takes a number and a list of some type a take' :: (Num i, Ord i) = i - [a] - [a] first, ignore the list and check whether n is = 0. in this case return an empty list. this is the base case, that's eventually reached by the recursion take' n _ | n = 0 = [] otherwise, check if the list is empty. this is another base case. take' _ [] = [] if neither n=0 or the list empty, take the first element, x, and put it on front of the prefix of length (n-1) of the other elements. use take' again, to get that prefix. after a while either n is 0 or there are no more elements in the list and we reach the base case take' n (x:xs) = x : take' (n-1) xs Take two lists zip' :: [a] - [b] - [(a,b)] if either one of them is empty, stop zip' _ [] = [] zip' [] _ = [] otherwise prepend a tuple, build from the two first elements to the zipped list of the other elements. after a while one of the lists should become empty and the base case is reached. zip' (x:xs) (y:ys) = (x,y):zip' xs ys quicksort :: (Ord a) = [a] - [a] empty list - nothing to do quicksort [] = [] quicksort (x:xs) = otherwise take the first element of the list and use it to split the list in two halves. one with all the elements that are smaller or equal than x, the other one with all those that are bigger. now sort them and put x in the middle. that should give us a sorted whole. how to sort them? just use quicksort again! after some splitting the lists will become empty and the recursion stops. let smallerSorted = quicksort [a | a - xs, a = x] biggerSorted = quicksort [a | a - xs, a x] in smallerSorted ++ [x] ++ biggerSorted -Inline Attachment Follows- ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- Message: 2 Date: Wed, 18 Mar 2009 07:54:22 + (UTC) From: 7stud bbxx789_0...@yahoo.com Subject: [Haskell-beginners] Re: Understanding recursion in
Beginners Digest, Vol 9, Issue 23
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: folds again -- myCycle (7stud) 2. Re: Re: folds again -- myCycle (Daniel Fischer) 3. Innovating control structures (Girish Bhat) 4. Re: Innovating control structures (Girish Bhat) 5. Re: folds again -- myCycle (7stud) 6. infix functions with 3 args (7stud) 7. Re: infix functions with 3 args (Thomas Davie) 8. Problems when trying to solve yaht exercise 3.10 (ZelluX) -- Message: 1 Date: Thu, 19 Mar 2009 19:32:19 + (UTC) From: 7stud bbxx789_0...@yahoo.com Subject: [Haskell-beginners] Re: folds again -- myCycle To: beginners@haskell.org Message-ID: loom.20090319t190853-...@post.gmane.org Content-Type: text/plain; charset=us-ascii Will Ness will_n48 at yahoo.com writes: In our case, having The access in (head ys) gets traslated in head ys = head (ys ++ [1,2,3]) = head ((ys ++ [1,2,3]) ++ [1,2,3]) but for the other defintion let zs = [1, 2, 3] ++ zs it's head zs = head([1, 2, 3] ++ zs) = head( (1:[2,3]) ++ zs) = head( 1:([2,3]++zs) ) = 1 according to the defintion of (++), (x:xs)++ys = x:(xs++ys) Were we to use the foldr definition, it'll get rewritten just the same, using the foldr definition (as long as it's not the left-recursive defintion): foldr f z (a:as) = a `f` foldr f z as let ws = foldr (:) [1,2,3] ws head ws = head (foldr (:) [1,2,3] ws) = head (foldr (:) [1,2,3] (foldr (:) [1,2,3] ws)) because 'ws' is getting matched against (a:as) pattern in foldr definition, so is immediately needed, causing INFINITE looping. BUT I'm confused by your statement that ws is getting matched against the (a:as) pattern in the foldr definition, and therefore it is immediately evaluated. I didn't think the let expression: let ws = foldr (:) [1,2,3] ws would cause infinite looping. Wouldn't it be the head pattern that is being matched, and therefore head triggers the evaluation? Although, I'm not seeing a pattern match here: head (x:xs) = x head (foldr (:) [1,2,3] (foldr (:) [1,2,3] ws)) .. ... ... .. .. ,,, ... -- Message: 2 Date: Thu, 19 Mar 2009 21:01:30 +0100 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] Re: folds again -- myCycle To: 7stud bbxx789_0...@yahoo.com, beginners@haskell.org Message-ID: 200903192101.30673.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-1 Am Donnerstag, 19. März 2009 20:32 schrieb 7stud: Will Ness will_n48 at yahoo.com writes: In our case, having The access in (head ys) gets traslated in head ys = head (ys ++ [1,2,3]) = head ((ys ++ [1,2,3]) ++ [1,2,3]) but for the other defintion let zs = [1, 2, 3] ++ zs it's head zs = head([1, 2, 3] ++ zs) = head( (1:[2,3]) ++ zs) = head( 1:([2,3]++zs) ) = 1 according to the defintion of (++), (x:xs)++ys = x:(xs++ys) Were we to use the foldr definition, it'll get rewritten just the same, using the foldr definition (as long as it's not the left-recursive defintion): foldr f z (a:as) = a `f` foldr f z as let ws = foldr (:) [1,2,3] ws head ws = head (foldr (:) [1,2,3] ws) = head (foldr (:) [1,2,3] (foldr (:) [1,2,3] ws)) because 'ws' is getting matched against (a:as) pattern in foldr definition, so is immediately needed, causing INFINITE looping. BUT I'm confused by your statement that ws is getting matched against the (a:as) pattern in the foldr definition, and therefore it is immediately evaluated. I didn't think the let expression: let ws = foldr (:) [1,2,3] ws would cause infinite looping. Note this is again the left recursive bad definition. As long as we don't want to know anything about ws, the definition ws = foldr (:) [1,2,3] ws sleeps peacefully. Wouldn't it be the head pattern that is being matched, and therefore head triggers the evaluation? If we need to know about the structure of ws, for example if we query head ws the evaluation of ws is triggered. In the case of head, we want to know if ws matches the pattern (_:_), in which case head returns the head of ws, or not, in which case head throws an exception. So the implementation tries to match ws with the pattern (_:_). To see if it matches, it must evaluate ws, first replacing ws by the right hand side of its definition, foldr (:) [1,2,3] ws. Doesn't yet say if ws matches (_:_), so the foldr must be evaluated. foldr (:) [1,2,3] [] ~ [1,2,3]
Beginners Digest, Vol 9, Issue 29
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Explicit specification of function types (Brandon S. Allbery KF8NH) 2. Re: Explicit specification of function types (Colin Adams) 3. Re: Explicit specification of function types (Felipe Lessa) 4. Re: Explicit specification of function types (Yitzchak Gale) 5. Re: Explicit specification of function types (Tommy M. McGuire) 6. Re: folds again -- myCycle (Will Ness) -- Message: 1 Date: Tue, 24 Mar 2009 00:55:41 -0400 From: Brandon S. Allbery KF8NH allb...@ece.cmu.edu Subject: Re: [Haskell-beginners] Explicit specification of function types To: Zachary Turner divisorthe...@gmail.com Cc: beginners@haskell.org Message-ID: 2ef310c2-8cc3-4795-94ff-42860b474...@ece.cmu.edu Content-Type: text/plain; charset=us-ascii Skipped content of type multipart/alternative-- next part -- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/beginners/attachments/20090324/b93baf51/PGP-0001.bin -- Message: 2 Date: Tue, 24 Mar 2009 07:29:29 + From: Colin Adams colinpaulad...@googlemail.com Subject: Re: [Haskell-beginners] Explicit specification of function types To: Zachary Turner divisorthe...@gmail.com Cc: beginners@haskell.org Message-ID: 1afdeaec0903240029j9bd9649g939a1ab26a8aa...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 2009/3/24 Zachary Turner divisorthe...@gmail.com: 2. Type inference is nice right up until you have to debug a type error; then the error gets reported at the point where the compiler realizes it can't match up the types, which could be somewhere not obviously related (depends on what the call chain looks like). The more concrete types you give the compiler, the better (both more complete and more correctly located) the type errors will be. Regarding the second issue, this occurs in most other type inferring languages as well, but usually you just specify types up until such time that your function is fully tested and you deem that it's good, then removing the type specification. This seems perverse to me. The type signature is very good documentation for other people wanting to use the function. Removing it is a very hostile activity. -- Message: 3 Date: Tue, 24 Mar 2009 08:32:34 -0300 From: Felipe Lessa felipe.le...@gmail.com Subject: Re: [Haskell-beginners] Explicit specification of function types To: beginners@haskell.org Message-ID: 20090324113234.gb9...@kira.casa Content-Type: text/plain; charset=us-ascii On Mon, Mar 23, 2009 at 09:02:56PM -0500, Zachary Turner wrote: Everything I've read has said that it's generally considered good practice to specify the full type of a function before the definition. Why is this? I've written some reasons not too long ago: http://www.haskell.org/pipermail/beginners/2009-February/001045.html Note that catching errors is probably the most useful benefit of writing type signatures. For a simple example, see -- f :: Int - Int f n = (n * 45 + 10) / 3 Do you see the problem? I've used (/) while I meant `div`. But, suppose you didn't write any type signature at all, the code would compile just fine with type 'f :: Floating a = a - a'. Now, in another module you say -- Type signature needed here to select what Read instance you want getNum :: IO Int getNum = read `fmap` getLine -- doF :: IO () doF = getNum = print . f Try it for yourself, what error message you get? The usual cryptic one about Fractional Int but *in the definition 'doF'*. Your *programmer mistake* propagated to another *module*. That is a bad, bad thing. Whenever you write type signatures, all these kinds of errors get contained inside the function they were written, saving you a lot of time. The second most important benefit probably would be to help you write the function itself. If you can't write the signature of your function, then you can't write your function at all. And it is not uncommon, even among experienced Haskellers, to write a type signature and then realise they were trying to do something completely wrong! Unfortunately I can't give you any example right now, but believe me. -- Felipe. -- Message: 4 Date: Tue, 24 Mar 2009 17:02:04 +0200 From: Yitzchak Gale
Beginners Digest, Vol 9, Issue 30
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Explicit specification of function types (Peter Verswyvelen) 2. Re: Explicit specification of function types (Zachary Turner) 3. Tutorial/Book with Exercises (Zachary Turner) 4. Event handling in GTK2hs: managing events andglobal state (?? ?. ) 5. Re: Event handling in GTK2hs: managing events andglobal state (Brandon S. Allbery KF8NH) -- Message: 1 Date: Wed, 25 Mar 2009 00:02:55 +0100 From: Peter Verswyvelen bugf...@gmail.com Subject: Re: [Haskell-beginners] Explicit specification of function types To: Brandon S. Allbery KF8NH allb...@ece.cmu.edu Cc: beginners@haskell.org Message-ID: a88790d10903241602v53ace185rdbfde185931a9...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 2009/3/24 Brandon S. Allbery KF8NH allb...@ece.cmu.edu That's my understanding, F++ types don't require any runtime lookups so inference can't surprise you. It uses .NET interfaces for that, but the F# expert book mentions they would like to have type classes in a future version of the language. in Haskell can do unexpected things: F++ has parenthesized function arguments, so it will catch too few/too many arguments directly, but Haskell's uncurried function call notation almost guarantees strange errors in those cases even if you have everything explicitly typed. Not really, F# has both curried and uncurried forms, just like Haskell. It is true that F# encourages automatic generalization without type signatures. You never need to give one, even for exported modules. But the lack of type classes has its price. E.g. add x y = x + y What is the type of add in F#? Well, that depends on the first usage of this function... Give it Ints and it becomes add :: Int - Int - Int, and you can't use it on Doubles any more. Very confusing, since you can use the overloaded (+) on any type. These are current limitations of the language. At least that what I understood from it... -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090325/10266608/attachment-0001.htm -- Message: 2 Date: Tue, 24 Mar 2009 19:51:06 -0500 From: Zachary Turner divisorthe...@gmail.com Subject: Re: [Haskell-beginners] Explicit specification of function types To: Peter Verswyvelen bugf...@gmail.com Cc: beginners@haskell.org Message-ID: 478231340903241751g6ecc795dm9456555b6690c...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 On Tue, Mar 24, 2009 at 6:02 PM, Peter Verswyvelen bugf...@gmail.comwrote: 2009/3/24 Brandon S. Allbery KF8NH allb...@ece.cmu.edu That's my understanding, F++ types don't require any runtime lookups so inference can't surprise you. It uses .NET interfaces for that, but the F# expert book mentions they would like to have type classes in a future version of the language. in Haskell can do unexpected things: F++ has parenthesized function arguments, so it will catch too few/too many arguments directly, but Haskell's uncurried function call notation almost guarantees strange errors in those cases even if you have everything explicitly typed. Not really, F# has both curried and uncurried forms, just like Haskell. It is true that F# encourages automatic generalization without type signatures. You never need to give one, even for exported modules. But the lack of type classes has its price. E.g. add x y = x + y What is the type of add in F#? Well, that depends on the first usage of this function... Give it Ints and it becomes add :: Int - Int - Int, and you can't use it on Doubles any more. Very confusing, since you can use the overloaded (+) on any type. These are current limitations of the language. At least that what I understood from it... What you say is partially true. For example, if delcared as you typed it, a rule similar to the monomorphism restriction (from what I understand of the monomorphism restriction) applies. If it's never used, x and y are of type int, and if they are used, x and y pick up the type of whatever you call it with. So doubles if you invoke it with 3.0 and 4.0, ints if you invoke it with 3 and 4, and an error if you invoke it once with doulbes and once with ints. The F# answer to this is to inline the function. For example: let inline add (x:'a) (y:'a) : 'a = x+y let
Beginners Digest, Vol 10, Issue 28
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Re: WWAAA... I hate monads (Daniel Carrera) 2. parser comparison question (Walck, Scott) 3. Re: Re: WWAAA... I hate monads (Joel Neely) -- Message: 1 Date: Fri, 24 Apr 2009 22:50:28 +0200 From: Daniel Carrera daniel.carr...@theingots.org Subject: Re: [Haskell-beginners] Re: WWAAA... I hate monads To: beginners@haskell.org Message-ID: 49f22614.5010...@theingots.org Content-Type: text/plain; charset=UTF-8; format=flowed Ertugrul Soeylemez wrote: Actually Schrödinger's cat is neither dead nor alive. Its state S is a unit vector living in a Hilbert space. I spoke imprecisely, but I do know about superposition. I took a couple of quantum courses when I got my physics degree (but generally I focused on astrophysics which is far more interesting than quantum mechanics). Daniel. -- Message: 2 Date: Fri, 24 Apr 2009 22:31:29 -0400 From: Walck, Scott wa...@lvc.edu Subject: [Haskell-beginners] parser comparison question To: beginners@haskell.org beginners@haskell.org Message-ID: e6c639c7e135d846b5127945421a789f164b760...@lvc02.lvc.edu Content-Type: text/plain; charset=us-ascii I've been comparing Graham Hutton's simple parser with Parsec. Here is some example code. -- Comparison of Hutton's simple parser with Parsec -- Hutton's simple parser is available at -- http://www.cs.nott.ac.uk/~gmh/Parsing.lhs -- Hutton simple parser called H -- Parsec called P import qualified Parsing as H import qualified Text.ParserCombinators.Parsec as P exH = H.parse (H.string hi) hiho exP = P.parse (P.string hi) hiho charH = H.parse (H.char 'a' H.+++ H.char 'b') bbb charP = P.parse (P.char 'a' P.| P.char 'b') bbb choiceH = H.parse (H.string hoo H.+++ H.string ho) hono choiceP1 = P.parse (P.string bb P.| P.string ba) bbb choiceP2 = P.parse (P.string ba P.| P.string bb) bbb choiceP22 = P.parse (P.try (P.string ba) P.| P.string bb) bbc I am interested if anyone could comment on the design of the Parsec 'try' function. For example, choiceP2 fails and returns Left error, while choiceP22 succeeds. Hutton's simple parser doesn't need try. It seems so simple and elegant. I'm wondering why Parsec requires me to use 'try' for a string parse that might fail. Thanks, Scott Scott N. Walck Associate Professor of Physics Lebanon Valley College -- Message: 3 Date: Fri, 24 Apr 2009 22:17:35 -0500 From: Joel Neely joel.ne...@gmail.com Subject: Re: [Haskell-beginners] Re: WWAAA... I hate monads To: j.romi...@gmail.com, beginners@haskell.org Message-ID: 5e0b968a0904242017v6c7d6c0cq35855361321ee...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 With Ertugrul's permission, I've done a simple print-to-PDF of his Understanding Haskell Monads tutorial, and am providing the PDF file to this list. -jn- On Fri, Apr 24, 2009 at 5:11 AM, j.romi...@gmail.com wrote: On Thu, Apr 23, 2009 at 09:42:56PM +0200, Ertugrul Soeylemez wrote: Hello people, thanks for all your positive comments about my tutorial, both here and through direct email. I appreciate that very much. =) I'm glad that my work is helpful to the community. Would you provide a PDF version along with the HTML version? Regards, Romildo Colin Paul Adams co...@colina.demon.co.uk wrote: Daniel == Daniel Carrera daniel.carr...@theingots.org writes: Daniel Sam Martin wrote: This is excellent: http://ertes.de/articles/monads.html Wow. That really is a great tutorial! Suddenly the world becomes clear... Definitely gets my vote as must read material. Daniel +1 Daniel I was very impressed too. And I am not easy to impress Daniel when it comes to documentation. I plan to read it a second Daniel time to solidify some of the ideas, but on my first Daniel reading my understanding of Monads increased by leaps and Daniel bounds. Daniel Ertugrul deserves to be commended, and this tutorial Daniel should be made more prominent on haskell.org. I think so. I've read VERY MANY tutorials on monads, and they were all confusing - except this one. ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- Beauty of style and harmony and grace and good rhythm depend on simplicity. - Plato
Beginners Digest, Vol 10, Issue 30
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Working With TVars (Brent Yorgey) 2. Problem install ghc 6.10.2 (aditya siram) -- Message: 1 Date: Tue, 28 Apr 2009 08:41:13 -0400 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] Working With TVars To: beginners@haskell.org Message-ID: 20090428124113.ga28...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii But getA returns an STM Int, so I still have to do a : doSomethingWithA = do a' - (getA mySTM) case a' of 1 - doStuff 0 - doSomethingElse This doesn't really save me a lot of boilerplate. What is the best way of writing a function that just returns my values do I can work with them in the STM monad without unpacking them all the time? You can't; that is the whole point. However, there are ways to save some typing. For example, you could use (=), which the do-notation desugars to anyway: doSomethingWithA = getA mySTM = \a' - case a' of ... In this case, that doesn't actually save that much, I guess. But you could go much further. For example, if you often find yourself doing case analysis on the value of a, you could write something like caseA :: STM e - STM e - STM e caseA act1 act2 = do a' - (getA mySTM) case a' of 1 - act1 0 - act2 Then you could just write 'caseA doStuff doSomethingElse'. And if you wanted something more general than just matching on 1 or 0, you could write (say) caseA' :: [(Int, STM e)] - STM e And so on. The trick is to abstract out the common patterns in your code. Haskell is really good at this---if you find yourself typing the same boilerplate over and over again, there's (often) a way to abstract out the commonality. -Brent -- Message: 2 Date: Tue, 28 Apr 2009 10:49:26 -0500 From: aditya siram aditya.si...@gmail.com Subject: [Haskell-beginners] Problem install ghc 6.10.2 To: beginners@haskell.org Message-ID: 594f78210904280849y58e0d1a6la6afa8d0da0ea...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 Hi all, I am trying to install the Linux GHC 6.10.2 binary, but when I fire up ghci I get the following error: GHCi, version 6.10.2: http://www.haskell.org/ghc/ :? for help Glasgow Haskell Compiler, Version 6.10.2, for Haskell 98, stage 2 booted by GHC version 6.10.1 Using package config file: /usr/local/lib/ghc-6.10.2/./package.conf wired-in package ghc-prim[] not found. wired-in package integer[] not found. wired-in package base[] not found. wired-in package rts mapped to rts-1.0 wired-in package haskell98[] not found. wired-in package syb[] not found. wired-in package template-haskell[] not found. wired-in package dph-seq[] not found. wired-in package dph-par[] not found. package haddock-2.4.2 will be ignored due to missing or recursive dependencies: Cabal-1.6.0.3 array-0.2.0.0 base-4.1.0.0 containers-0.2.0.1 directory-1.0.0.3 filepath-1.1.0.2 ghc-6.10.2 haskell98-1.0.1.0 pretty-1.0.1.0 package ghc-6.10.2 will be ignored due to missing or recursive dependencies: Cabal-1.6.0.3 array-0.2.0.0 base-4.1.0.0 bytestring-0.9.1.4 containers-0.2.0.1 directory-1.0.0.3 editline-0.2.1.0 filepath-1.1.0.2 haskell98-1.0.1.0 hpc-0.5.0.3 old-time-1.0.0.2 process-1.0.1.1 template-haskell-2.3.0.1 unix-2.3.2.0 Hsc static flags: -static *** Deleting temp files: Deleting: *** Deleting temp dirs: Deleting: ghc: panic! (the 'impossible' happened) (GHC version 6.10.2 for i386-unknown-linux): interactiveUI:setBuffering2 Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug Running ghc-pkg check gave me : There are problems in package haddock-2.4.2: dependency Cabal-1.6.0.3 doesn't exist dependency array-0.2.0.0 doesn't exist dependency base-4.1.0.0 doesn't exist dependency containers-0.2.0.1 doesn't exist dependency directory-1.0.0.3 doesn't exist dependency filepath-1.1.0.2 doesn't exist dependency haskell98-1.0.1.0 doesn't exist dependency pretty-1.0.1.0 doesn't exist There are problems in package ghc-6.10.2: dependency Cabal-1.6.0.3 doesn't exist dependency array-0.2.0.0 doesn't exist dependency base-4.1.0.0 doesn't exist dependency bytestring-0.9.1.4 doesn't exist dependency containers-0.2.0.1 doesn't exist dependency directory-1.0.0.3 doesn't exist dependency editline-0.2.1.0 doesn't exist dependency filepath-1.1.0.2 doesn't exist dependency haskell98-1.0.1.0 doesn't exist dependency hpc-0.5.0.3 doesn't
Beginners Digest, Vol 10, Issue 31
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Working With TVars (Brandon S. Allbery KF8NH) 2. International Summer School on Advances in Programming Languages (vo...@tcs.inf.tu-dresden.de) -- Message: 1 Date: Tue, 28 Apr 2009 16:02:50 -0400 From: Brandon S. Allbery KF8NH allb...@ece.cmu.edu Subject: Re: [Haskell-beginners] Working With TVars To: aditya siram aditya.si...@gmail.com Cc: beginners@haskell.org Message-ID: 687b50c3-69e9-42f0-b870-5064ddf5e...@ece.cmu.edu Content-Type: text/plain; charset=us-ascii Skipped content of type multipart/alternative-- next part -- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/beginners/attachments/20090428/689a08eb/PGP-0001.bin -- Message: 2 Date: Wed, 29 Apr 2009 21:00:28 +0200 (MEST) From: vo...@tcs.inf.tu-dresden.de Subject: [Haskell-beginners] International Summer School on Advances in Programming Languages To: beginners@haskell.org Message-ID: 839f2e88adda3a8cd59b480d49900d28.squir...@mail.tcs.inf.tu-dresden.de Content-Type: text/plain; charset=iso-8859-1 International Summer School on Advances in Programming Languages 25th-28th August, 2009 Heriot-Watt University, Edinburgh, Scotland http://www.macs.hw.ac.uk/~greg/ISS-AiPL Overview This four-day residential International Summer School on Advances in Programming Languages has a major theme of Concurrency, Distribution, and Multicore. Intended primarily for postgraduate research students, the School offers lectures and practical sessions on an engaging blend of cutting edge theoretical and practical techniques from international experts. The Summer School is supported by the Scottish Informatics and Computer Science Alliance (http://www.sicsa.ac.uk/), a Scottish Funding Council Research Pool. Participants from SICSA member institutions may attend at no cost. Confirmed Topics/Speakers - Static and dynamic languages, Prof Phillip Wadler, University of Edinburgh - Compiler technology for data-parallel languages, Dr Sven-Bodo Scholz, University of Hertfordshire - New applications of parametricity, Dr Janis Voigtlaender, Technical University of Dresden - Automatic vectorising compilation, Dr Paul Cockshott, University of Glasgow - Foundational aspects of size analysis, Prof Marko van Eekelen/Dr Olha Shakaravska, Radboud University Nijmegen - Context oriented programming, Dr Pascal Costanza, Vrije Universiteit Brussel - Multi-core programming, Dr Phil Trinder, Heriot-Watt University - Multi-core compilation, Dr Alastair Donaldson, Codeplay Software Ltd - Principles and Applications of Refinement Types, Dr Andrew D. Gordon, Microsoft Research, Cambridge - Resource aware programming in Hume, Prof Greg Michaelson, Heriot-Watt University/ Prof Kevin Hammond, University of St Andrews - Haskell concurrency parallelism, Dr Satnam Singh, Microsoft Research, Cambridge Location The Summer School is based at Heriot-Watt University's Riccarton campus, set in pleasant parkland to the west of Edinburgh, with easy access to the airport, city and central Scotland: http://www.hw.ac.uk/welcome/directions.htm. The Summer School immediately precedes the 2009 International Conference on Functional Programming (http://www.cs.nott.ac.uk/~gmh/icfp09.html) and takes place during the Edinburgh International Festival (http://www.eif.co.uk/), and the associated Edinburgh Festival Fringe (http://www.edfringe.com/) and Edinburgh International Book Festival (http://www.edbookfest.co.uk/). Steering Committee Prof Greg Michaelson, Heriot-Watt University (Convenor) (mailto:g.michael...@hw.ac.uk) Prof Kevin Hammond, University of St Andrews Dr Patricia Johann, University of Strathclyde Prof Phillip Wadler, University of Edinburgh -- next part -- A non-text attachment was scrubbed... Name: SICSA ISS AiPL.pdf Type: application/download Size: 34222 bytes Desc: not available Url : http://www.haskell.org/pipermail/beginners/attachments/20090429/a6c43702/SICSAISSAiPL.bin -- next part -- A non-text attachment was scrubbed... Name: SICSA ISS AiPL Programme.pdf Type: application/download Size: 5515 bytes Desc: not available Url :
Beginners Digest, Vol 11, Issue 7
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. gcd (Steve) 2. Re: parallel program in haskell in 5 steps (Sean Bartell) 3. How to wait till a process is finished beforeinvoking the next one? (Thomas Friedrich) 4. Re: How to wait till a process is finished beforeinvoking the next one? (Daniel Fischer) 5. Re: How to wait till a process is finished beforeinvoking the next one? (Thomas Friedrich) 6. Real World Haskell Chapter 5 (PJ Fitzpatrick) 7. Re: How to wait till a process is finished beforeinvoking the next one? (Daniel Fischer) 8. Re: Real World Haskell Chapter 5 (Daniel Fischer) 9. Re: How to wait till a process is finished beforeinvoking the next one? (Brandon S. Allbery KF8NH) -- Message: 1 Date: Fri, 01 May 2009 21:30:35 +0800 From: Steve stevech1...@yahoo.com.au Subject: [Haskell-beginners] gcd To: beginners@haskell.org Message-ID: 1241184635.4876.18.ca...@host.localdomain Content-Type: text/plain I had a look at the gcd definition in GHC 6.10.1 ghc-6.10.1/libraries/base/GHC/Real.lhs -- | @'gcd' x y@ is the greatest (positive) integer that divides both @x@ -- and @y@; for example @'gcd' (-3) 6@ = @3@, @'gcd' (-3) (-6)@ = @3@, -- @'gcd' 0 4@ = @4...@. @'gcd' 0 0@ raises a runtime error. gcd :: (Integral a) = a - a - a gcd 0 0 = error Prelude.gcd: gcd 0 0 is undefined gcd x y = gcd' (abs x) (abs y) where gcd' a 0 = a gcd' a b = gcd' b (a `rem` b) Why is gcd 0 0 undefined? http://en.wikipedia.org/wiki/Greatest_common_divisor says: It is useful to define gcd(0, 0) = 0 and lcm(0, 0) = 0 because then the natural numbers become a complete distributive lattice with gcd as meet and lcm as join operation. This extension of the definition is also compatible with the generalization for commutative rings given below. An added advantage, for haskell, of defining gcd 0 0 = 0 is that gcd would change from being a partial function to a total function. Regards, Steve -- Message: 2 Date: Wed, 6 May 2009 23:25:43 -0400 From: Sean Bartell wingedtachik...@gmail.com Subject: Re: [Haskell-beginners] parallel program in haskell in 5 steps To: Jack Kennedy j...@realmode.com Cc: beginners@haskell.org Message-ID: dd3762960905062025j33c302q7eeb9107ffc52...@mail.gmail.com Content-Type: text/plain; charset=utf-8 Does this happen for everyone, or just me? I get the same result here. Changing a to fib 100 lets me get 65-75%. The compiler's probably just being smarter than you expect and combining both instances of ack 4 10. -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090506/7b6f0769/attachment-0001.htm -- Message: 3 Date: Thu, 07 May 2009 12:36:08 -0400 From: Thomas Friedrich i...@suud.de Subject: [Haskell-beginners] How to wait till a process is finished before invoking the next one? To: beginners@haskell.org Message-ID: 4a030df8.3040...@suud.de Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi everyone, I have the following problem, and I hope that someone of yours might be able to help me. The Haskell program I am writing has the following setup: writeData :: [String] - IO () writeData cs = ... runProgram:: [String] - IO () runProgram cs = ... writeFeatures :: [String] - IO () writeFeatures cs = ... runTestOnFeatures :: IO () runTestOnFeatures = ... main :: IO () main = do cs - getArgs writeData cs runProgram cs writeFeatures cs runTestOnFeatures Each of the above function take a list of filenames, run certain command-line programs on them, which I invoke by runCommand, and each of them produce multiple output-files. Each function in main needs a couple of those output-files that are produced by the function directly above it. How do I get Haskell to wait, till all the data is written to the disk, before invoking the next command. The way the program is currently written, Haskell doesn't see that the input of one function depends on the output of another, and tries to run them all at the same time. Any ideas? Thanks everyone for your help. Cheers, Thomas -- Message: 4 Date: Thu, 7 May 2009 19:10:49 +0200 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re:
Beginners Digest, Vol 11, Issue 8
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Pros and Cons of Haskell libsndfile packages? (Charles Turner) 2. Re: Pros and Cons of Haskell libsndfile packages? (Erik de Castro Lopo) 3. Re: Pros and Cons of Haskell libsndfile packages? (Charles Turner) 4. A Quantity Type - Integer without the Negative #'s (aditya siram) 5. Re: A Quantity Type - Integer without theNegative #'s (Daniel Fischer) 6. Re: A Quantity Type - Integer without the Negative #'s (Daniel Carrera) 7. Re: A Quantity Type - Integer without the Negative #'s (Magnus Therning) 8. Re: A Quantity Type - Integer without theNegative #'s (Alexander Dunlap) 9. SQL Lexer (Patrick LeBoutillier) 10. Re: A Quantity Type - Integer without theNegative #'s (Ashok Gautham) -- Message: 1 Date: Thu, 07 May 2009 19:06:37 -0400 From: Charles Turner vze26...@optonline.net Subject: [Haskell-beginners] Pros and Cons of Haskell libsndfile packages? To: beginners@haskell.org Message-ID: 5f197860-d089-4387-9c75-e95259b54...@optonline.net Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Hi all- I noticed that there were two different packages that provided a Haskell interface to the libsndfile library: HSoundFile: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HSoundFile hsoundfile: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hsndfile Does anyone have any comments of the relative merits of either of these? Thanks! Charles -- Message: 2 Date: Fri, 8 May 2009 10:09:25 +1000 From: Erik de Castro Lopo mle...@mega-nerd.com Subject: Re: [Haskell-beginners] Pros and Cons of Haskell libsndfile packages? To: beginners@haskell.org Message-ID: 20090508100925.37745149.mle...@mega-nerd.com Content-Type: text/plain; charset=US-ASCII Charles Turner wrote: Hi all- I noticed that there were two different packages that provided a Haskell interface to the libsndfile library: hsndfile: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hsndfile That one is a indeed a haskell wrapper around libsndfile, while this one: HSoundFile: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HSoundFile is not, but rather, seems to be a pure Haskell Wave file decoder/encoder. It does not (yet) seem to handle other formats. Does anyone have any comments of the relative merits of either of these? I'm probably biased, but I'm sure the former (hsndfile) opens more file formats and is more robust when parsing malformed files. Erik -- -- Erik de Castro Lopo http://www.mega-nerd.com/ -- Message: 3 Date: Fri, 08 May 2009 13:40:55 -0400 From: Charles Turner vze26...@optonline.net Subject: Re: [Haskell-beginners] Pros and Cons of Haskell libsndfile packages? To: beginners@haskell.org Message-ID: 38590b26-3068-4ecb-a4ef-1f1b847b8...@optonline.net Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes On May 7, 2009, at 8:09 PM, Erik de Castro Lopo wrote: Charles Turner wrote: That one is a indeed a haskell wrapper around libsndfile, while this one: HSoundFile: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HSoundFile Does anyone have any comments of the relative merits of either of these? I'm probably biased, but I'm sure the former (hsndfile) opens more file formats and is more robust when parsing malformed files. Hi Erik! In this case I think your bias is well-appreciated. Thanks so much for libsndfile, always one the first libraries I install on any new machine. Best, Charles -- Message: 4 Date: Fri, 8 May 2009 13:22:23 -0500 From: aditya siram aditya.si...@gmail.com Subject: [Haskell-beginners] A Quantity Type - Integer without the Negative#'s To: beginners beginners@haskell.org Message-ID: 594f78210905081122l31cc683aof7c0661c6ff56...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 Hi all, Is there a datatype in Haskell that can be used to represent only quantities = 0? I got bitten by a bug because I forgot to reject an amount that was below zero after applying a decrementing operator. A simple unit test would have caught this, but I was wondering if there was some way of getting the type
Beginners Digest, Vol 11, Issue 11
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: defining 'init' in terms of 'foldr' (Heinrich Apfelmus) 2. Re: defining 'init' in terms of 'foldr' (Daniel Fischer) 3. The main thread and waiting for other threads (Thomas Friedrich) 4. Re: The main thread and waiting for other threads (Daniel Fischer) 5. Re: The main thread and waiting for other threads (Rafael Gustavo da Cunha Pereira Pinto) 6. Re: The main thread and waiting for other threads (Quentin Moser) 7. International Summer School on Advances in Programming Languages (precedes ICFP'09) (Janis Voigtlaender) -- Message: 1 Date: Tue, 12 May 2009 13:31:32 +0200 From: Heinrich Apfelmus apfel...@quantentunnel.de Subject: [Haskell-beginners] Re: defining 'init' in terms of 'foldr' To: beginners@haskell.org Message-ID: gubmmi$r4...@ger.gmane.org Content-Type: text/plain; charset=ISO-8859-1 Michael Mossey wrote: In S. Thompson's book, problem 9.13 asks us to define 'init' in terms of foldr. I was baffled at first because I didn't see a natural way to do this. It would look something like init xs = foldr f initialValue xs where f would cons on each character except the rightmost. f when passed rightmost char b = [] f when passed any other char a b = a : b How does f know when it is passed the first character? initialValue has to signal this somehow. On #haskell, one person suggested doing it with some post-processing: init xs = snd $ foldr f (True,[]) xs where f _ (True,_) = (False,[]) f a (False,b) = (False,a:b) I had an idea. If the initial value is the entire list, then its length can function as the signal that we are dealing with the rightmost char. This requires no post-processing: init xs = foldr f xs xs where f a b | length b == length xs = [] | otherwise = a:b These seem contrived. I wonder if there is a more natural solution that Thompson had in mind. Any comments? It is best to see foldr f b as an operation that takes a list x0 : x1 : x2 : ... : [] and replaces every (:) with f and the [] with b : x0 `f` x1 `f` x2 `f` ... `f` b See also http://en.wikipedia.org/wiki/Fold_(higher-order_function) for Cale's nice pictures. It is then clear that we have to choose b to signal the end of the list. Furthermore, b should be the same as init [] . Unfortunately, this expression is a run-time error, but this is a fault of the type signature init :: [a] - [a] which should really be init' :: [a] - Maybe [a] to make it clear that some lists like the empty one simply don't have an initial segment. And this version has a natural implementation in terms of foldr : init' = foldr f Nothing where f _ Nothing = Just [] f x (Just xs) = Just (x:xs) Of course, we need some post-processing to obtain the original init from this, but I think that it's very natural. Regards, apfelmus -- http://apfelmus.nfshost.com -- Message: 2 Date: Tue, 12 May 2009 14:27:30 +0200 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] defining 'init' in terms of 'foldr' To: beginners@haskell.org Message-ID: 200905121427.30834.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-1 Am Montag 11 Mai 2009 16:13:36 schrieb Michael Mossey: In S. Thompson's book, problem 9.13 asks us to define 'init' in terms of foldr. Check the thread starting at http://www.haskell.org/pipermail/haskell-cafe/2005-April/009562.html That contains several interesting approaches, though I don't think any of those was lazy enough to deal with infinite lists. I was baffled at first because I didn't see a natural way to do this. It would look something like init xs = foldr f initialValue xs Since *FoldInit init [] *** Exception: Prelude.init: empty list initialValue has to be (error Prelude.init: empty list) if you don't do any post- processing. But then init [1] = f 1 (error ...) must be [], so f can't inspect its second argument (or it would return _|_ instead of []), but then you can't make init [1] = f 1 (error ...) return [] and also init [1,2] = f 1 (f 2 (error ...)) return [1]. So some post-processing is necessary. where f would cons on each character except the rightmost. f when passed rightmost char b = [] f when passed any other char a b = a : b How does f know when it is passed the first character? initialValue has to
Beginners Digest, Vol 11, Issue 19
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Haskell Generic Function Question (William Gilbert) 2. Re: Haskell Generic Function Question (Paul Visschers) 3. Re: Haskell Generic Function Question (Ertugrul Soeylemez) 4. Re: Haskell Generic Function Question (Thomas Friedrich) 5. Re: Haskell Generic Function Question (Jeff Wheeler) 6. Case Expressions (Nathan Holden) 7. Re: Case Expressions (Brent Yorgey) 8. Re: Haskell Generic Function Question (Jan Jakubuv) 9. Re: Case Expressions (Dean Herington) 10. Re: Case Expressions (Thomas Friedrich) -- Message: 1 Date: Thu, 28 May 2009 11:50:36 -0400 From: William Gilbert gilber...@gmail.com Subject: [Haskell-beginners] Haskell Generic Function Question To: beginners@haskell.org Message-ID: a928161a0905280850r7751f0d4m1b41cda7eb32...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 I am trying to write a function that will covert either an integer or an int into a list containing its digits. ex. toIntegralList 123 - [1,2,3] I have written the following definition that tries to use read to generically cast a string value to an Integral type that is the same as the Integral passed in: toIntegralList :: (Integral a) = a - [a] toIntegralList x = map (\c - read [c] :: a) (show x) I understand it would be very simple to just create two functions, one that converts an Int and one that converts an Integer, however I was wondering if there were any way to accomplish what I am trying to do here. Thanks In Advance, Bryan -- Message: 2 Date: Thu, 28 May 2009 18:49:15 +0200 From: Paul Visschers m...@paulvisschers.net Subject: Re: [Haskell-beginners] Haskell Generic Function Question To: William Gilbert gilber...@gmail.com Cc: beginners@haskell.org Message-ID: 4a1ec08b.3060...@paulvisschers.net Content-Type: text/plain; charset=ISO-8859-1 I assume the problem is that the function doesn't compile. This should work: toIntegralList :: (Read a, Show a) = a - [a] toIntegralList x = map (\c - read [c]) (show x) This adds the required Read and Show instances, which are necessary because of the read and show functions, respectively. Also note that I have omitted your extra type annotation, which also causes an compile error. The problem with this functions is that you can use it on a lot of stuff that isn't a number, and you'll get a runtime read error, to remedy this, just reinsert the Integral type class requirement: toIntegralList :: (Integral a, Read a, Show a) = a - [a] toIntegralList x = map (\c - read [c]) (show x) Hope this helps, Paul William Gilbert wrote: I am trying to write a function that will covert either an integer or an int into a list containing its digits. ex. toIntegralList 123 - [1,2,3] I have written the following definition that tries to use read to generically cast a string value to an Integral type that is the same as the Integral passed in: toIntegralList :: (Integral a) = a - [a] toIntegralList x = map (\c - read [c] :: a) (show x) I understand it would be very simple to just create two functions, one that converts an Int and one that converts an Integer, however I was wondering if there were any way to accomplish what I am trying to do here. Thanks In Advance, Bryan ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- Message: 3 Date: Thu, 28 May 2009 18:55:06 +0200 From: Ertugrul Soeylemez e...@ertes.de Subject: [Haskell-beginners] Re: Haskell Generic Function Question To: beginners@haskell.org Message-ID: 20090528185506.1e62c...@tritium.xx Content-Type: text/plain; charset=US-ASCII William Gilbert gilber...@gmail.com wrote: I am trying to write a function that will covert either an integer or an int into a list containing its digits. ex. toIntegralList 123 - [1,2,3] I have written the following definition that tries to use read to generically cast a string value to an Integral type that is the same as the Integral passed in: toIntegralList :: (Integral a) = a - [a] toIntegralList x = map (\c - read [c] :: a) (show x) I understand it would be very simple to just create two functions, one that converts an Int and one that converts an Integer, however I was wondering if there were any way to accomplish what I am trying to do here. Of course you can use read and show
Beginners Digest, Vol 12, Issue 1
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Maybe a and Maybe t (Ivan Uemlianin) 2. Re: Maybe a and Maybe t (Daniel Fischer) 3. A try on a bank machine algorithm... (Bernhard Lehnert) 4. Re: Maybe a and Maybe t (Brent Yorgey) 5. Re: A try on a bank machine algorithm... (Alexander Dunlap) 6. Re: Maybe a and Maybe t (Ivan Uemlianin) 7. Re: A try on a bank machine algorithm... (Thomas Friedrich) 8. Re: A try on a bank machine algorithm... (Brent Yorgey) -- Message: 1 Date: Sun, 31 May 2009 14:37:27 +0100 From: Ivan Uemlianin i...@llaisdy.com Subject: Re: [Haskell-beginners] Maybe a and Maybe t Cc: beginners@haskell.org Message-ID: 4a228817.2060...@llaisdy.com Content-Type: text/plain; charset=UTF-8; format=flowed Dear Andrew and Lee Thanks for your comments. Andrew Wagner wrote: As for why it actually happens in this case, it's no doubt related to the particular algorithm ghci uses to do the type inference. Interesting. I tried it in hugs and it doesn't happen: Main :type safeSecond safeSecond :: [a] - Maybe a Main :type tidySecond tidySecond :: [a] - Maybe a Main So, it's a property of the ghci interpreter rather than of the language itself. Just out of curiousity, I'd be interested to know what's going on in ghci to produce this effect. Are there different types of type variable? Learning Haskell is reminding me of things I studied when I was an undergrad (linguistics)--- pattern matching in Prolog; the type system reminds me of categorial grammar; we looked at lamda calculus as part of formal semantics. So I'd like to look into this more deeply, if anyone can give me a pointer into the ghci docs. Thanks again Ivan -- Ivan A. Uemlianin Speech Technology Research and Development i...@llaisdy.com www.llaisdy.com llaisdy.wordpress.com www.linkedin.com/in/ivanuemlianin Froh, froh! Wie seine Sonnen, seine Sonnen fliegen (Schiller, Beethoven) -- Message: 2 Date: Sun, 31 May 2009 17:42:44 +0200 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] Maybe a and Maybe t To: beginners@haskell.org Message-ID: 200905311742.45381.daniel.is.fisc...@web.de Content-Type: text/plain; charset=utf-8 Am Sonntag 31 Mai 2009 15:37:27 schrieb Ivan Uemlianin: Dear Andrew and Lee Thanks for your comments. Andrew Wagner wrote: As for why it actually happens in this case, it's no doubt related to the particular algorithm ghci uses to do the type inference. In particular the part where GHC assigns names to type variables. Interesting. I tried it in hugs and it doesn't happen: Main :type safeSecond safeSecond :: [a] - Maybe a Main :type tidySecond tidySecond :: [a] - Maybe a Main So, it's a property of the ghci interpreter rather than of the language itself. Yes. Just out of curiousity, I'd be interested to know what's going on in ghci to produce this effect. Are there different types of type variable? There are type variables of different *kind*, e.g. in class Functor f where fmap :: (a - b) - f a - f b a and b are type variables of kind * (the kind of ordinary types) and f is a type variable of kind (* - *) (the kind of type constructors which take an ordinary type and produce another ordinary type, examples are [] and Maybe). But that has nothing to do with the phenomenon, in the inferred type signatures of safeSecond and tidySecond, the 'a' resp. 't' are both type variables of kind *. The only difference is that in one case the name supply delivered 'a' and in the other it delivered 't'. -- Message: 3 Date: Sun, 31 May 2009 23:19:02 +0200 From: Bernhard Lehnert b.lehn...@gmx.de Subject: [Haskell-beginners] A try on a bank machine algorithm... To: beginners beginners@haskell.org Message-ID: 1243804742.10638.2.ca...@sol Content-Type: text/plain Hi, in a Python Forum someone came up with his homework. Just beginning to learn Haskell I thougt I give it a try. I came up with a working function that I present here to ask you, if I am doing this right or how I could do better. The job was: A cash machine has to compute the division of bank notes for any given amount of
Beginners Digest, Vol 12, Issue 4
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: type classes and multiple implementations (Chadda? Fouch?) 2. timer_create: Invalid argument (Thomas Friedrich) 3. Re: timer_create: Invalid argument (Daniel Fischer) 4. Re: timer_create: Invalid argument (Maur??cio) 5. Re: Re: timer_create: Invalid argument (Thomas Friedrich) 6. Re: timer_create: Invalid argument (Maur??cio) 7. exercise 3.10 in YAHT (George Huber) 8. Re: exercise 3.10 in YAHT (Fernando Henrique Sanches) -- Message: 1 Date: Sat, 6 Jun 2009 18:00:50 +0200 From: Chadda? Fouch? chaddai.fou...@gmail.com Subject: Re: [Haskell-beginners] type classes and multiple implementations To: Sean Bartell wingedtachik...@gmail.com Cc: beginners@haskell.org Message-ID: e9350eaf0906060900l713faeabl47c8ef38d7e16...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Fri, Jun 5, 2009 at 7:09 PM, Sean Bartellwingedtachik...@gmail.com wrote:   by_type :: Storage a = String - String - IO a This function must, for any Storage type, take any two strings and produce an IO value of that type. (by_type disk xyz :: Memory must be valid.) It doesn't really have the option of choosing which instance of Storage to use. In pure Haskell, you would probably have to do something like  type Storage = Disk Handle | Memory String  by_type :: String - String - Storage That way, by_type can return any Storage it wants. I'm sure there are also ways to do what you want with extensions. I think the point is to be able to extend the storage methods in another module ? If not, Sean's solution is what you want. If you want to use the type class to allow anyone to add a new method in his own module, you can use existential type, like : data Store = forall a . Storage a = Store a and then your byType : byType disk x = Store (open x :: Disk) byType memory x = Store (open x :: Memory) See XMonad and its Layout type for an example of this method. -- Jedaï -- Message: 2 Date: Mon, 08 Jun 2009 10:35:22 -0400 From: Thomas Friedrich i...@suud.de Subject: [Haskell-beginners] timer_create: Invalid argument To: beginners beginners@haskell.org Message-ID: 4a2d21aa.2090...@suud.de Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi, I need to check if a couple of files have the same number of lines in them. So, I written a little Haskell program that counts the number of lines in a file. import System.Environment (getArgs) main :: IO () main = do [f] - getArgs cs - readFile f print $ length (lines cs) Now, when I invoke the program on my computer, it does what it should do: ~ $ ./count count.hs 7 However, when I run the program on a different computer, I get the following: ~ $ scp count count.hs thom...@...:~ tho...@...'s password: count100% 492KB 492.2KB/s 00:00 count.hs 100% 125 0.1KB/s 00:00 ~ $ ssh tho...@... [tho...@... ~] $ ./count count.hs count: timer_create: Invalid argument [tho...@... ~]$ What does this error message mean? And why does it occur? Other programs that I written and compiled on my computer worked just fine on the other. I run Arch Linux and I am using GHC 6.10.3, the other computer is a RedHat 3. Cheers, Thomas -- Message: 3 Date: Mon, 8 Jun 2009 17:17:33 +0200 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] timer_create: Invalid argument To: beginners@haskell.org Message-ID: 200906081717.33765.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-1 Am Montag 08 Juni 2009 16:35:22 schrieb Thomas Friedrich: Hi, [tho...@... ~] $ ./count count.hs count: timer_create: Invalid argument [tho...@... ~]$ What does this error message mean? And why does it occur? Other programs that I written and compiled on my computer worked just fine on the other. I run Arch Linux and I am using GHC 6.10.3, the other computer is a RedHat 3. Do other Haskell programmes compiled with ghc-6.10.3 on Arch run on Red Hat 3? I think the timer_create is called during initialisation of the run-time, for +RTS -sstderr and such, probably RH3 has an older timer_create which doesn't like the passed argument. Then no ghc-compiled programme from Arch should run on RH3, nor should C programmes using timer_create with like arguments. Cheers, Thomas -- Message: 4 Date:
Beginners Digest, Vol 12, Issue 8
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: ghci reports The last statement in a 'do' construct must be an expression error (Nico Rolle) 2. Re: xml parsing (Antoine Latter) 3. Modifications inside a Reader? (Brian Troutwine) 4. Re: xml parsing (Yitzchak Gale) 5. Re: map increases length of list (Jack Kennedy) 6. Re: map increases length of list (Daniel Fischer) -- Message: 1 Date: Wed, 17 Jun 2009 18:13:03 +0200 From: Nico Rolle nico.ro...@googlemail.com Subject: Re: [Haskell-beginners] ghci reports The last statement in a 'do'construct must be an expression error To: Daniel Fischer daniel.is.fisc...@web.de Cc: beginners@haskell.org Message-ID: 45fccde20906170913t1fe143c3q26f8008cd37b1...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 it really was an indentation error i configured my editor to expand tabs into spaces but somehow he did a real tab on line 9 and 10 thank you 2009/6/16 Daniel Fischer daniel.is.fisc...@web.de Am Dienstag 16 Juni 2009 22:35:17 schrieb Nico Rolle: Hi Heres my code snippet. It reports that my error is in line 9 right after the main definition. All functions that i call work under normal circumstances. Thanks Must be the indentation, probably the xs is indented further than the following line (though that's not the case for the code copy-pasted from the mail to an editor). But note that this will most likely print out 0 twice. The let pnp = ... bindings don't cause any computation to occur. To measure the time the computations take, you must force them to occur between the two calls to getCurrentTime. module Benchmark where import ReadCSV import Operators import Data.Time.Clock (diffUTCTime, getCurrentTime) main = do xs - readCSV dataconvert/lineitem.tbl '|' start - getCurrentTime let pnp = projection [5] xs let snp = selection (\x - (x!!0) (Int 17000)) pnp end - getCurrentTime putStrLn $ show (end `diffUTCTime` start) start2 - getCurrentTime let pp = pProjection [5] xs let sp = pSelection (\x - (x!!0) (Int 17000)) pp end2 - getCurrentTime putStrLn $ show (end2 `diffUTCTime` start2) return xs ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090617/c37de581/attachment-0001.html -- Message: 2 Date: Wed, 17 Jun 2009 22:32:50 -0500 From: Antoine Latter aslat...@gmail.com Subject: Re: [Haskell-beginners] xml parsing To: Benedikt Ahrens benedikt.ahr...@gmx.net Cc: beginners@haskell.org Message-ID: 694519c50906172032r23e7b0b2xe6439e9e2de46...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jun 17, 2009 at 1:05 PM, Benedikt Ahrensbenedikt.ahr...@gmx.net wrote: Hello, I want to write a program which among other should read some xml file. The xml tags will mostly be custom ones defined by a dtd. My question is: which parsing library to use? On http://en.wikibooks.org/wiki/Haskell/XML three libraries are mentioned, but a comparison and recommendation of which one to choose is missing. As you might imagine, I would like to use a library which is actively maintained? Has any of these libraries developed into a standard library? Thanks in advance for your help. ben One option I've used before which isn't on the list is on hackage here: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/xml I have a parser for these XML files: http://cgit.freedesktop.org/xcb/proto/tree/src in this Haskell package on hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/xcb-types I'm no Haskell guru, and the code may not be the best example - but the library is pretty easy to get started with. Antoine -- Message: 3 Date: Wed, 17 Jun 2009 20:32:53 -0700 From: Brian Troutwine goofyheadedp...@gmail.com Subject: [Haskell-beginners] Modifications inside a Reader? To: beginners@haskell.org Message-ID: 971980cc0906172032v5b9a9ad2l5ea0ea4fc878b...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 Hello all. I'm writing a UDP echo server, full source given below. The current implementation echoes back the payload of
Beginners Digest, Vol 12, Issue 10
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: question on layout (Maur??cio) 2. decorate-sort-undecorate in haskell (Ivan Uemlianin) 3. FoldL/R Reducing List (Waaaggh) 4. Re: decorate-sort-undecorate in haskell (Daniel Fischer) 5. Re: FoldL/R Reducing List (Daniel Fischer) 6. Re: FoldL/R Reducing List (Waaaggh) 7. Re: FoldL/R Reducing List (Chadda? Fouch?) 8. Updating lists inside another list (Aaron MacDonald) 9. Re: Updating lists inside another list (Lee Duhem) -- Message: 1 Date: Sun, 21 Jun 2009 15:25:13 -0300 From: Maur??cio briqueabra...@yahoo.com Subject: [Haskell-beginners] Re: question on layout To: beginners@haskell.org Message-ID: h1ltu9$8v...@ger.gmane.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed do a - x let b = a y b z expands to do {a - x ; let {b = a} in do {y b z}} I'm curious as to where the second `do' came from? Well, the above translation isn't quite correct, the second 'do' wouldn't come until later. The point is that 'do { let x = y; foo }' translates to 'let x = y in do { foo }'. Exatly, I should have checked better that example. I just thought it worth to show how 'let' translates in a 'do' expression, because it caused me a lot of trouble when I learned Haskell. Since I had read that 'do' expressions are supposed to chain (Monad m) = (m a) elements, I assumed from this use of 'let' that: (WARNING: WRONG ASSUMPTIONS!) * 'let a = b' has type (Monad m) = (m x), x the type of a and b. * Since 'let' is used in let expressions and also in do expressions, either Haskell allows redefinition of reserved keywords or 'let' is not a reserved keyword and there's some way in Haskell to define constructs like 'let ... in ...' using more basic primitives. * Haskell has some kind of overloading allowing one word to be used in unrelated contexts. That's of course completely nonsense, but I would be happy if I could avoid others from running into this kind of misunderstanding. Best, Maurício -- Message: 2 Date: Mon, 22 Jun 2009 11:03:02 +0100 From: Ivan Uemlianin i...@llaisdy.com Subject: [Haskell-beginners] decorate-sort-undecorate in haskell To: beginners@haskell.org Message-ID: 4a3f56d6.2090...@llaisdy.com Content-Type: text/plain; charset=ISO-8859-1; format=flowed Dear All I'm learning Haskell from a background in Python, and I'm just looking at the sort and sortBy functions in Data.List. In Python, the decorate-sort-undecorate pattern is a popular alternative to using an explicit compare function. For example, to sort a list of lists by length: def sortByLength(xs): dec_xs = [(len(x), x) for x in xs] dec_xs.sort() undec_xs = [x[1] for x in dec_xs] return undec_xs This is often preferred to something like: xs.sort(lambda x,y: len(x) len(y)) # just used lambda so it fits on one line I think the reasoning is that plain sort() is done at C speed, whereas sort(func) is done in Python, so, depending on the list I suppose, dsu can be worth the trouble. (Sorry for vagueness). Anyway, I was wondering if dsu is popular in Haskell, and whether or when it would make sense to use dsu rather than sortBy. Here's a verbose dsu I wrote myself: sortDSU decFunc a = undecorate (sort (decorate decFunc a)) decorate decFunc [] = [] decorate decFunc (x:xs) = ( ((decFunc x), x) : decorate decFunc xs ) undecorate [] = [] undecorate ( (_, y) :xs) = ( y : undecorate xs ) Here's a terser and perhaps more idiomatic (but I think equivalent) dsu which I then found in a comment at the Real World Haskell website: dsuSort decFunc a = map snd (sort (zip (map decFunc a) a)) I have tested both functions with length and sum in ghci. So, do Haskell programmers use the decorate-sort-undecorate pattern? If not, why not? If so, when? Thanks and best wishes Ivan -- Ivan A. Uemlianin Speech Technology Research and Development i...@llaisdy.com www.llaisdy.com llaisdy.wordpress.com www.linkedin.com/in/ivanuemlianin Froh, froh! Wie seine Sonnen, seine Sonnen fliegen (Schiller, Beethoven) -- Message: 3
Beginners Digest, Vol 12, Issue 11
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Updating lists inside another list (Lee Duhem) 2. Re: decorate-sort-undecorate in haskell (Brandon S. Allbery KF8NH) 3. Re: decorate-sort-undecorate in haskell (Henk-Jan van Tuyl) 4. Re: decorate-sort-undecorate in haskell (Daniel Fischer) 5. Re: decorate-sort-undecorate in haskell (Ivan Uemlianin) 6. HXT: Gathering text from Nodes (aditya siram) 7. [SOLVED]Re: HXT: Gathering text from Nodes (aditya siram) 8. lhs2TeX (Thomas Friedrich) 9. Re: decorate-sort-undecorate in haskell (Brandon S. Allbery KF8NH) -- Message: 1 Date: Tue, 23 Jun 2009 15:19:50 +0800 From: Lee Duhem lee.du...@gmail.com Subject: Re: [Haskell-beginners] Updating lists inside another list To: Joel Neely joel.ne...@gmail.com Cc: beginners beginners@haskell.org Message-ID: da43c2e0906230019h5c37f8c5pdd4640de758b7...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Tue, Jun 23, 2009 at 11:29 AM, Joel Neelyjoel.ne...@gmail.com wrote: WRT the first case, I would have expected something like; addToInnerList [] a b = [(a,[b])] on the assumption that one grows a structure from an empty state. Your thoughts? I think it isn't what Aaron wants, that is to add an element to the inner list of the pair with the head value of my choosing. Anyway, it is an option. lee -- Message: 2 Date: Tue, 23 Jun 2009 08:58:11 -0400 From: Brandon S. Allbery KF8NH allb...@ece.cmu.edu Subject: Re: [Haskell-beginners] decorate-sort-undecorate in haskell To: Ivan Uemlianin i...@llaisdy.com Cc: beginners@haskell.org Message-ID: ebb8fa24-8555-42cb-99fc-8c5e08cb9...@ece.cmu.edu Content-Type: text/plain; charset=us-ascii On Jun 22, 2009, at 06:03 , Ivan Uemlianin wrote: I'm learning Haskell from a background in Python, and I'm just looking at the sort and sortBy functions in Data.List. In Python, the decorate-sort-undecorate pattern is a popular alternative to using an explicit compare function. For example, to sort a list of lists by It's fairly common, considering that decorate-sort-undecorate is a functional programming idiom dating back to Lisp. In Haskell it's usually expressed with the decoration in a tuple such that the default sort can be used. map snd . sort . map (\x - (x,decorate x)) Fancier versions use arrows to make the decorate part cleaner: map snd . sort . map (decorate id) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH -- next part -- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/beginners/attachments/20090623/d0874055/PGP-0001.bin -- Message: 3 Date: Tue, 23 Jun 2009 15:42:59 +0200 From: Henk-Jan van Tuyl hjgt...@chello.nl Subject: Re: [Haskell-beginners] decorate-sort-undecorate in haskell To: Brandon S. Allbery KF8NH allb...@ece.cmu.edu, Ivan Uemlianin i...@llaisdy.com Cc: beginners@haskell.org Message-ID: op.uvzcdysypz0...@zen5.router.home Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 On Tue, 23 Jun 2009 14:58:11 +0200, Brandon S. Allbery KF8NH allb...@ece.cmu.edu wrote: On Jun 22, 2009, at 06:03 , Ivan Uemlianin wrote: I'm learning Haskell from a background in Python, and I'm just looking at the sort and sortBy functions in Data.List. In Python, the decorate-sort-undecorate pattern is a popular alternative to using an explicit compare function. For example, to sort a list of lists by It's fairly common, considering that decorate-sort-undecorate is a functional programming idiom dating back to Lisp. In Haskell it's usually expressed with the decoration in a tuple such that the default sort can be used. map snd . sort . map (\x - (x,decorate x)) Fancier versions use arrows to make the decorate part cleaner: map snd . sort . map (decorate id) The simplest form for e.g. sorting by length is: sortByLength = sortBy (comparing length) -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://functor.bamikanarie.com http://Van.Tuyl.eu/ -- -- Message: 4 Date: Tue, 23 Jun 2009
Beginners Digest, Vol 12, Issue 12
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: lhs2TeX (Daniel Seidel) 2. Re: [xmonad] xmonad vs. full screen (Thomas Friedrich) 3. High precision doubles (Aaron MacDonald) 4. Re: High precision doubles (Andrew Hunter) 5. Re: High precision doubles (Aaron MacDonald) 6. Re: High precision doubles (Sean Bartell) 7. Re: Re: [xmonad] xmonad vs. full screen (styx) 8. Re: High precision doubles (Daniel Fischer) 9. Re: High precision doubles (Rafael Gustavo da Cunha Pereira Pinto) -- Message: 1 Date: Wed, 24 Jun 2009 08:47:04 +0200 From: Daniel Seidel seid...@tcs.inf.tu-dresden.de Subject: Re: [Haskell-beginners] lhs2TeX To: Thomas Friedrich i...@suud.de Cc: beginners beginners@haskell.org Message-ID: 4a41cbe8.50...@tcs.inf.tu-dresden.de Content-Type: text/plain; charset=ISO-8859-1; format=flowed Thomas Friedrich wrote: Hi everyone, A Google-search wasn't successful, that's why I am asking here. I want to use the program lhs2TeX. In the manual it says there are different styles that you can use, and some examples how they look like. But they never say how to call them. If I like to see the verbatim-style or the tt-style. What do I include in my document? Hi, lhs2TeX --verb input.lhs output.tex or everything else instead of --verb. It is explained in http://people.cs.uu.nl/andres/lhs2TeX-IFIP.pdf Greetings, Daniel. -- Message: 2 Date: Wed, 24 Jun 2009 18:38:30 -0400 From: Thomas Friedrich i...@suud.de Subject: [Haskell-beginners] Re: [xmonad] xmonad vs. full screen To: beginners beginners@haskell.org Message-ID: 4a42aae6.10...@suud.de Content-Type: text/plain; charset=ISO-8859-1; format=flowed Rickard Nilsson wrote: Quoting Thomas Friedrich i...@suud.de: 2) I would propose going back to the old behavior of handling full-screen-programs in xmonad. It really should be the *user* who decides how full-screen a full-screen-program shall be. Isn't this also more following the philosophy of xmonad? You as a user decide, what is happening on your screen? It might be not as intuitive, when switching to xmonad and you are used to other WMs, where full-screen means *full screen*. I really miss that functionality, now that its gone. What do you think? I think the old behaviour made much more sense. As it is now, it's not possible to play a web flash movie in a separate, arbitrarily sized, window. You either have to watch it fullscreen-floating, or integrated in the web-page. @Thomas - Did you ever manage to revert Xmonad to the old behaviour? No unfortunately I didn't. I changed my manageHook to myManageHookDef = scratchpadManageHook (W.RationalRect 0.25 0.375 0.5 0.35) + composeAll [ ... , isFullscreen -- doFullFloat , isDialog -- doCenterFloat ] This way, when I want to watch a Flash-Movie in full screen, the video window actually covers the full screen. However, the downside of it is that also xpdf and others start flouting when going to full screen. Which is stupid, as I always have to push them back into the tiling, when I want to have a full screen xpdf next to, say, emacs. Also you will have a little border around the flouting window, which doesn't look good in full screen. But I don't want to remove the borders from flouting windows, as I like to have a border, when a flouting window is not covering the whole screen. So as you see, the solution is far from optimal. Cheers, Thomas -- Message: 3 Date: Wed, 24 Jun 2009 20:46:04 -0300 From: Aaron MacDonald aaro...@eastlink.ca Subject: [Haskell-beginners] High precision doubles To: beginners@haskell.org Message-ID: ac540dfe-f2e4-4976-a4dc-78038ddb2...@eastlink.ca Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Is there anything in Haskell that can represent doubles with higher precision than the regular kind? I'm working with formulas that generate sets of values, and values that I know should be zero are ending up as things like -7.105427357601002e-15 or -1.7763568394002505e-14, which is causing all kinds of butterfly effects. I've heard of Rational, but I need to also work with irrational numbers (namely, pi and anything that comes from cos and sin). What other options do I have? - Aaron -- Message: 4 Date: Wed, 24 Jun 2009 18:18:19 -0700 From:
Beginners Digest, Vol 12, Issue 13
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: High precision doubles (Rafael Gustavo da Cunha Pereira Pinto) 2. if True than let... (Bernhard Lehnert) 3. Re: if True than let... (Andrew Wagner) 4. Re: if True than let... (John Melesky) 5. Re: if True than let... (Gracjan Polak) 6. Re: if True than let... (Bernhard Lehnert) 7. Re: if True than let... (Daniel Fischer) 8. Re: High precision doubles (a...@spamcop.net) 9. on (Ivan Uemlianin) -- Message: 1 Date: Thu, 25 Jun 2009 10:38:44 -0300 From: Rafael Gustavo da Cunha Pereira Pinto rafaelgcpp.li...@gmail.com Subject: Re: [Haskell-beginners] High precision doubles To: beginners@haskell.org Message-ID: 351ff25e0906250638l549aaf1y3de0b980f8468...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 oops: Relative exit condition (valid only when dealing with non-zero values) abs ((xold-xnew)/xnew) epsilon On Thu, Jun 25, 2009 at 10:24, Rafael Gustavo da Cunha Pereira Pinto rafaelgcpp.li...@gmail.com wrote: I am reading this and still don't understand what is the question. You should never operate two floating point numbers expecting to result zero. Period. Floating point numbers are intrinsically imprecise. Every time you write an interactive process with floating points in the exit conditions, you should use some tolerance, either relative or absolute. Absolute exit condition: abs (xnew - xold) epsilon Relative exit condition (valid only when dealing with non-zero values) abs ((xold+xnew)/xnew) epsilon If you cannot apply this, then either: 1) You are dealing with VERY small values, close to the minimal precision (2.2250738585072014e-308, on 64-bit doubles), 2) You are dealing with small and big numbers, differing by 37 orders of magnitude amongst them, when the small number will be set to 0 To solve this you should: for 1) Scale your numbers... double, multiply by 1024, whatever, as long as they separate from the minimal precision. It is like putting your maze under a HUGE microscope! for 2) Addition in situations as this one is like adding a pinch of salt on the ocean. For multiplications, try using Log-domain operations... That might work... Praying might work as well... Where epsilon is On Thu, Jun 25, 2009 at 09:17, Daniel Fischer daniel.is.fisc...@web.dewrote: Am Donnerstag 25 Juni 2009 04:14:19 schrieb Sean Bartell: When adding a new node/hex to the graph/maze, I pick an existing node and get all of its neighbour co-ordinates, filtering out co-ordinates that represent nodes already present in the graph. The problem is that, due to floating point errors, these co-ordinates are not be exact. If hex A has the co-ordinate for hex B in its list of adjacent hexes, hex B would not necessarily have the co-ordinate for hex A in its own list. Things get mismatched quickly. You won't be able to get it working easily with floating-point numbers. Ideally, you would use integers for the code you're describing, then scale them to the proper floating-point values later. Say the hexagons have side length 2, the centre of one is at (0,0) and one of its vertices at (2,0). Then the centre of any hexagon has coordinates (3*k,m*sqrt 3), for some integers k, m and any vertex has coordinates (i,j*sqrt 3) for integers i, j. So in this case, he could work with floating point values; using a large tolerance, he could build a gigantic grid before having false results. But of course, it is much better to use (k,m), resp. (i,j), as coordinates and translate that to floating point only for drawing. ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- Rafael Gustavo da Cunha Pereira Pinto Electronic Engineer, MSc. -- Rafael Gustavo da Cunha Pereira Pinto Electronic Engineer, MSc. -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090625/3f274a5e/attachment-0001.html -- Message: 2 Date: Thu, 25 Jun 2009 22:12:08 +0200 From: Bernhard Lehnert b.lehn...@gmx.de Subject: [Haskell-beginners] if True than let... To: beginners@haskell.org Message-ID: 1245960728.6635.60.ca...@sol Content-Type: text/plain Hi, I'm sorry because I am absolutely sure, this is bloody obvious to the knowing.
Beginners Digest, Vol 12, Issue 14
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: on (Erlend Hamberg) 2. Re: on (Ivan Uemlianin) 3. Re: High precision doubles (Rafael Gustavo da Cunha Pereira Pinto) 4. Re: if True than let... (Heinrich Apfelmus) 5. Re: Re: if True than let... (Andrew Wagner) 6. Gtk2Hs and Cairo on Windows (Philippe D.-P.) 7. Re: Gtk2Hs and Cairo on Windows (Maur??cio) 8. Re: [Haskell-cafe] What is an expected type... (Joe Fredette) -- Message: 1 Date: Fri, 26 Jun 2009 11:24:24 +0200 From: Erlend Hamberg ehamb...@gmail.com Subject: Re: [Haskell-beginners] on To: beginners@haskell.org Message-ID: ac30b3780906260224r34b3bb4arb0b30a4a7eb93...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 2009/6/26 Ivan Uemlianin i...@llaisdy.com: My question is: what is on? I'm afraid I haven't been able to find anything about this, no doubt because of all the false positives coming up in searches. http://www.haskell.org/hoogle/?hoogle=on -- Erlend Hamberg ehamb...@gmail.com -- Message: 2 Date: Fri, 26 Jun 2009 10:27:47 +0100 From: Ivan Uemlianin i...@llaisdy.com Subject: Re: [Haskell-beginners] on To: beginners@haskell.org Message-ID: 4a449493.5000...@llaisdy.com Content-Type: text/plain; charset=ISO-8859-1; format=flowed Erlend Hamberg wrote: 2009/6/26 Ivan Uemlianin i...@llaisdy.com: My question is: what is on? I'm afraid I haven't been able to find anything about this, no doubt because of all the false positives coming up in searches. http://www.haskell.org/hoogle/?hoogle=on Wow that was fast! Thanks, I hadn't tried Hoogle before and what I needed was the top hit: http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Function.html#v%3Aon Ivan -- Ivan A. Uemlianin Speech Technology Research and Development i...@llaisdy.com www.llaisdy.com llaisdy.wordpress.com www.linkedin.com/in/ivanuemlianin Froh, froh! Wie seine Sonnen, seine Sonnen fliegen (Schiller, Beethoven) -- Message: 3 Date: Fri, 26 Jun 2009 07:52:03 -0300 From: Rafael Gustavo da Cunha Pereira Pinto rafaelgcpp.li...@gmail.com Subject: Re: [Haskell-beginners] High precision doubles To: beginners@haskell.org Message-ID: 351ff25e0906260352u3d84de0auc5d48a4825890...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 Point noted, it doesn't seem to be the case for the original question, as he is doing some square roots. On Fri, Jun 26, 2009 at 04:00, a...@spamcop.net wrote: G'day all. Quoting Rafael Gustavo da Cunha Pereira Pinto rafaelgcpp.li...@gmail.com : I am reading this and still don't understand what is the question. You should never operate two floating point numbers expecting to result zero. Period. WARNING: Advanced material follows. A 32-bit integer fits losslessly in the mantissa of a Double. Any of the basic integer operations which work correctly on 32-bit integers must also work correctly when that integer is stored in a Double. You are allowed to assume this. Cheers, Andrew Bromage ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- Rafael Gustavo da Cunha Pereira Pinto Electronic Engineer, MSc. -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090626/7ab78cc4/attachment-0001.html -- Message: 4 Date: Fri, 26 Jun 2009 13:30:22 +0200 From: Heinrich Apfelmus apfel...@quantentunnel.de Subject: [Haskell-beginners] Re: if True than let... To: beginners@haskell.org Message-ID: h22bgb$34...@ger.gmane.org Content-Type: text/plain; charset=ISO-8859-1 Andrew Wagner wrote: Try this: let b = if a == True then + else - in ... The little figurine of Dijkstra in my head is urging me to write this as let b = if a then + else - in ... instead. ;) Regards, apfelmus -- http://apfelmus.nfshost.com -- Message: 5 Date: Fri, 26 Jun 2009 08:50:40 -0400 From: Andrew Wagner wagner.and...@gmail.com Subject: Re: [Haskell-beginners] Re: if True than let... To: Heinrich
Beginners Digest, Vol 12, Issue 16
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: [Haskell-cafe] What is an expected type... (michael rice) 2. Re: High precision doubles (Felipe Lessa) 3. Re: Rigid type variables match error (Felipe Lessa) 4. Re: High precision doubles (Matthew Eastman) 5. GHC compiling for different platforms (Bernhard Lehnert) 6. Re: GHC compiling for different platforms (Magnus Therning) -- Message: 1 Date: Sun, 28 Jun 2009 09:39:37 -0700 (PDT) From: michael rice nowg...@yahoo.com Subject: [Haskell-beginners] Re: [Haskell-cafe] What is an expected type ... To: Brandon S. Allbery KF8NH allb...@ece.cmu.edu Cc: beginners@haskell.org, Haskell Cafe mailing list haskell-c...@haskell.org Message-ID: 892836.55819...@web31108.mail.mud.yahoo.com Content-Type: text/plain; charset=iso-8859-1 How else? ;-) Thanks, Michael --- On Sun, 6/28/09, Brandon S. Allbery KF8NH allb...@ece.cmu.edu wrote: From: Brandon S. Allbery KF8NH allb...@ece.cmu.edu Subject: Re: [Haskell-cafe] What is an expected type ... To: michael rice nowg...@yahoo.com Cc: Brandon S. Allbery KF8NH allb...@ece.cmu.edu, Joe Fredette jfred...@gmail.com, beginners@haskell.org, Haskell Cafe mailing list haskell-c...@haskell.org Date: Sunday, June 28, 2009, 12:06 PM On Jun 28, 2009, at 12:02 , michael rice wrote:dec2bin :: Integer - [Integer] dec2bin n = dec2bin' n [] where dec2bin' n acc | n == 0 = acc | otherwise = let r = rem n 2 m = div (n - r) 2 in dec2bin' m (r : acc) is there any way to assign a type signature to the helper function? Same way you do for a top level binding: dec2bin :: Integer - [Integer] dec2bin n = dec2bin' n [] where dec2bin' :: Integer - [Integer] - [Integer] dec2bin' n acc | n == 0 = acc | otherwise = let r = rem n 2 m = div (n - r) 2 in dec2bin' m (r : acc) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.comsystem administrator [openafs,heimdal,too many hats] allb...@ece.cmu.eduelectrical and computer engineering, carnegie mellon university KF8NH -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090628/f1f2fb7e/attachment-0001.html -- Message: 2 Date: Sun, 28 Jun 2009 23:55:54 -0300 From: Felipe Lessa felipe.le...@gmail.com Subject: Re: [Haskell-beginners] High precision doubles To: beginners@haskell.org Message-ID: 20090629025554.ga22...@kira.casa Content-Type: text/plain; charset=us-ascii On Sun, Jun 28, 2009 at 10:34:51PM -0400, Matthew Eastman wrote: Just for fun, one of the mazes it made: ___ ___ ___ ___ ___ ___/ \___/ \___/ \___/ \___/ \___ / \ \ / / / \ \ \ \___/___/___/ / \ / / \___/___\ \___/ \ / \ \ / \___/ \ / \ / \___\ / / /___/ \___/___\___/ \ \___/ / \___\___/ \___\ / / \ /___ ___/ \___/ \ \___\___/ \ \ /___/ /___\___/ \___/ \___/ \___\ \___/ \___/ \___/ \___/ \___/ \___/ This is beautiful! Do you plan releasing something to Hackage? -- Felipe. -- Message: 3 Date: Mon, 29 Jun 2009 00:09:23 -0300 From: Felipe Lessa felipe.le...@gmail.com Subject: Re: [Haskell-beginners] Rigid type variables match error To: beginners@haskell.org Message-ID: 20090629030923.gb22...@kira.casa Content-Type: text/plain; charset=us-ascii On Sat, Jun 27, 2009 at 10:18:02AM +0930, Darryn wrote: class A a where a1 :: a a2 :: a - a a3 :: (B b) = b - a It is clear here that 'b' is different from 'a' on 'a3's definition, right? Now let's rename 'b' to 'c' on your instance: -- note that 'a = Ainst c' here. instance (B c) = A (Ainst c) where a1 :: Ainst c a1 = I a2 :: Ainst c - Ainst c a2 = J a3 :: (B b) = b - Ainst c a3 = ... Oops! We have 'K :: (B b) = b - Ainst b', but 'a3 :: (B b) = b - Ainst c' is more general than that. Hope that helps, -- Felipe. -- Message: 4 Date: Mon, 29 Jun 2009
Beginners Digest, Vol 13, Issue 1
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: GHC compiling for different platforms (Bernhard Lehnert) 2. Re: GHC compiling for different platforms (Colin Adams) 3. Re: GHC compiling for different platforms (Sean Bartell) 4. Re: GHC compiling for different platforms (Magnus Therning) 5. Re: GHC compiling for different platforms (Felipe Lessa) 6. Re: GHC compiling for different platforms (Magnus Therning) 7. Re: GHC compiling for different platforms (Felipe Lessa) 8. ghc profiler beginner (Jos? Prous) 9. Problems with IO actions (Adam Bergmark) 10. Is there a replacement for network-minihttp that allows lazy downloads? (Adam Bergmark) -- Message: 1 Date: Tue, 30 Jun 2009 06:31:14 +0200 From: Bernhard Lehnert b.lehn...@gmx.de Subject: Re: [Haskell-beginners] GHC compiling for different platforms To: Magnus Therning mag...@therning.org Cc: beginners@haskell.org Message-ID: 1246336274.3472.3.ca...@sol Content-Type: text/plain Am Montag, den 29.06.2009, 23:05 +0100 schrieb Magnus Therning: I don't think you'll have any success in running a 64-bit executable on a 32 bit system. Any chances to compile for a 32 bit linux on a 64 bit Linux or do I need an extra computer? Any other problems such as Intel/AMD/... or just 32bit/64bit? -- Message: 2 Date: Tue, 30 Jun 2009 05:34:23 +0100 From: Colin Adams colinpaulad...@googlemail.com Subject: Re: [Haskell-beginners] GHC compiling for different platforms To: Bernhard Lehnert b.lehn...@gmx.de Cc: Magnus Therning mag...@therning.org, beginners@haskell.org Message-ID: 1afdeaec0906292134v3171e8f0j6afd0c1a4faa2...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 You certainly don't need an extra computer, as you could run 32-bit Linux in a VM. 2009/6/30 Bernhard Lehnert b.lehn...@gmx.de: Am Montag, den 29.06.2009, 23:05 +0100 schrieb Magnus Therning: I don't think you'll have any success in running a 64-bit executable on a 32 bit system. Any chances to compile for a 32 bit linux on a 64 bit Linux or do I need an extra computer? Any other problems such as Intel/AMD/... or just 32bit/64bit? ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- Message: 3 Date: Tue, 30 Jun 2009 01:39:49 -0400 From: Sean Bartell wingedtachik...@gmail.com Subject: Re: [Haskell-beginners] GHC compiling for different platforms To: Bernhard Lehnert b.lehn...@gmx.de Cc: Magnus Therning mag...@therning.org, beginners@haskell.org Message-ID: dd3762960906292239h5ed30f7w763243b5a1d05...@mail.gmail.com Content-Type: text/plain; charset=utf-8 I'm guessing the easiest way would be to download a 32-bit precompiled version of GHC and use that. It should work if you have 32-bit libraries installed, which your distro probably does by default. I don't know about Haskell, but in C you could set up a chroot (your distro might have docs). You could also try compiling Haskell yourself and messing with configuration options. Intel vs. AMD shouldn't make a difference. -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090630/863415c9/attachment-0001.html -- Message: 4 Date: Tue, 30 Jun 2009 07:02:28 +0100 From: Magnus Therning mag...@therning.org Subject: Re: [Haskell-beginners] GHC compiling for different platforms To: beginners@haskell.org Message-ID: 4a49aa74.4070...@therning.org Content-Type: text/plain; charset=utf-8 Colin Adams wrote: You certainly don't need an extra computer, as you could run 32-bit Linux in a VM. Yes, going the VM route is probably easiest. IIRC Virtualbox can now run 64-bit guests on a 32-bit host, so you'd be able to provide executables for both no matter what you run on your main system. There was a call for a pre-made VM for Haskell development a while back (I think it was raised on haskell-cafe). I'm not sure anything came of it, but it'd be worth searching through the archives to see if you can avoid installing guests yourself. /M -- Magnus Therning(OpenPGP: 0xAB4DFBA4) magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org http://therning.org/magnus identi.ca|twitter: magthe -- next part -- A non-text attachment was
Beginners Digest, Vol 13, Issue 5
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: help with types and composition (Dan Douglas) 2. Re: help with types and composition (Edward Z. Yang) 3. Re: help with types and composition (Thomas Davie) 4. Re: Help with 20 intermediate haskell exercises (Patrick LeBoutillier) 5. guitar tuner alike (Bernhard Lehnert) 6. Re: guitar tuner alike (Joe Fredette) 7. Re: Help with 20 intermediate haskell exercises (Brent Yorgey) 8. Re: guitar tuner alike (Brent Yorgey) 9. Understanding State (Geoffrey Marchant) -- Message: 1 Date: Mon, 06 Jul 2009 08:30:46 CDT From: Dan Douglas doug0...@metnet.edu Subject: Re: [Haskell-beginners] help with types and composition To: beginners@haskell.org Message-ID: 200907061330.n66dukuc006...@tove.metnet.edu Content-Type: TEXT/plain; CHARSET=US-ASCII Ah silly me I think I sorta get it. after looking up currying this somewhat makes sense (it isn't really mentioned in YAHT and not till later in most other books.) So, basically any function's type will always be in curryfied form, and the only time there's a tuple involved is if the function's argument is itself a tuple? I'll have to ponder a bit how nesting functions are equivalent to a function with multiple arguments. Sorry about the messed up Unicode. That question doesn't really make sense knowing this. On 6 Jul 2009, Daniel Fischer wrote: Am Montag 06 Juli 2009 13:53:01 schrieb Dan Douglas: Hello everyone! first post here. I'm working through YAHT and Real World Haskell sort of in parallel. I have a somewhat related question. Assume we have a binary operator which is not a higher order function. The greater than relation for example: Prelude List :t () () :: forall a. (Ord a) = a - a - Bool Type classes and variables make sense - I assume since we have quantifiers, the type classes must be essentially predicates, and the type variables are bound to them as expected. Also I assume whenever we see (a - b) this means roughly f:(domain - codomain) Correct. a - a - Bool could therefore mean either: a function whose domain is an 'a' and whose codomain is a function from a to bool; Yes, that's it. or a function which takes a function from type 'a' to 'a' and returns a bool. That would be the type (a - a) - Bool. According to YAHT: NOTE The parentheses are not necessary; in function types, if you have a - b - y it is assume that b - y is grouped. If you want the other way, with a - b grouped, you need to put parentheses around them. In short: (-) is right associative, a - b - c - d === a - (b - (c - d)) I'm confused by this. A function which takes multiple arguments should be equivalent to a predicate bound to some n-tuple. Or in this case of a binary infix operator, equivalent to a prefix operator which takes a tuple. Correct. But, (a, a) is not equivalent to (a - a), Indeed it isn't, the two sets don't even have the same cardinality (except a contains only one element). But (a - a) - Bool is *not* equivalent to a - (a - Bool). and (a - Bool) just doesn't make sense as a range. But it does. (a - Bool) is a perfectly reasonable set/Haskell type. Functions whose result is a function are very common in functional programming. It should be something like: () :: forall a. (Ord a) = (a, a) - Bool Note that, (ignoring _|_ and partial functions), the types ((a,b) - c) and (a - (b - c)) are isomorphic. The isomorphism is given by curry :: ((a,b) - c) - (a - (b - c)) curry f = \x y - f (x,y) and uncurry :: (a - (b - c)) - ((a,b) - c) uncurry g = \(x,y) - g x y Someone on freenode told me that if you had: foo :: a - b bar :: b - c baz :: c - d and: bork = (baz . bar . foo) then: bork :: a - d Yup. Which, if correct means Haskell should always chain types for first-order functions. And since () is transitive, it should satisfy #8704;x#8704;y#8704;z(((x,y) #8712; R (y,z) #8712; R) - (x,z) #8712; R) and omit the case for (y,z). ??? How it is possible to express a function which takes multiple arguments (or any first-order function at all) with more than one arrow/map symbol? How does this even make sense? It gets even worse with more complicated examples: Prelude List :t foldl foldl :: forall a b. (a - b - a) - a - [b] - a Prelude List :t (=) (=) :: forall (m :: * - *) a
Beginners Digest, Vol 13, Issue 7
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: List.sort (John Dorsey) 2. Re: The Applicative instance for ((-) a) (Heinrich Apfelmus) 3. Re: List.sort (Patrick LeBoutillier) 4. Re: List.sort (Chadda? Fouch?) 5. Re: List.sort (Patrick LeBoutillier) 6. Re: List.sort (Geoffrey Marchant) 7. external sort (Keith Sheppard) 8. Re: external sort (Felipe Lessa) -- Message: 1 Date: Sat, 11 Jul 2009 09:17:04 -0400 From: John Dorsey hask...@colquitt.org Subject: Re: [Haskell-beginners] List.sort To: beginners@haskell.org Message-ID: 20090711131704.gr23...@colquitt.org Content-Type: text/plain; charset=us-ascii I sent this only to Patrick by mistake. Sorry for the duplicate, Patrick. -- Patrick, Ord a = [a] - [a] I don't understand how this type can allow it to sort pairs: Prelude :m +List Prelude List sort [(1, 1), (3, 3), (2, 2)] [(1,1),(2,2),(3,3)] How can a pair by of type Ord a? Is it a rule that the first element is automatically used? Ord a isn't really the type of a pair... it's a type *constraint* on the argument to the sort function, which is otherwise any type a. So it means List.sort can be applied to any type a which satisfies Ord a. But what does that mean? It means that there is an instance for the typeclass Ord for whatever type is given to Listsort. In the case of pairs, it's exactly as you guessed... the leftmost parts are compared first. This is so because somewhere there's an instance Ord (a,b) that defines how to compare pairs, and it does it that way (left-to-right). (And this generalizes to tuples bigger than pairs, up to some compiler-specific limit.) Does this make sense? John -- Message: 2 Date: Sat, 11 Jul 2009 17:53:20 +0200 From: Heinrich Apfelmus apfel...@quantentunnel.de Subject: [Haskell-beginners] Re: The Applicative instance for ((-) a) To: beginners@haskell.org Message-ID: h3ach3$3e...@ger.gmane.org Content-Type: text/plain; charset=ISO-8859-1 Ian Duncan wrote: Hey folks, I understand most of what is going on with the applicative class, but I can't figure out why this instance is useful: instance Applicative ((-) a) where... Can anyone offer some intuition into how this is could be used? As hinted to in the paper on applicative functors, Applicative programming with effects Conor McBride, Ross Paterson. http://strictlypositive.org/IdiomLite.pdf the instance functors are the S and K combinators. http://en.wikipedia.org/wiki/SKI_combinator_calculus Regards, apfelmus -- http://apfelmus.nfshost.com -- Message: 3 Date: Sat, 11 Jul 2009 11:57:10 -0400 From: Patrick LeBoutillier patrick.leboutill...@gmail.com Subject: Re: [Haskell-beginners] List.sort To: John Dorsey hask...@colquitt.org Cc: beginners@haskell.org Message-ID: b217a64f0907110857p5bbeb29eif851c846abcac...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 Hi, Patrick, Ord a = [a] - [a] I don't understand how this type can allow it to sort pairs: Prelude :m +List Prelude List sort [(1, 1), (3, 3), (2, 2)] [(1,1),(2,2),(3,3)] How can a pair by of type Ord a? Is it a rule that the first element is automatically used? Ord a isn't really the type of a pair... it's a type *constraint* on the argument to the sort function, which is otherwise any type a. So it means List.sort can be applied to any type a which satisfies Ord a. But what does that mean? It means that there is an instance for the typeclass Ord for whatever type is given to Listsort. In the case of pairs, it's exactly as you guessed... the leftmost parts are compared first. This is so because somewhere there's an instance Ord (a,b) that defines how to compare pairs, and it does it that way (left-to-right). (And this generalizes to tuples bigger than pairs, up to some compiler-specific limit.) Does this make sense? Yes, perfectly. I guess you just have to know about it... :) John ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- = Patrick LeBoutillier Rosemère, Québec, Canada -- Message: 4 Date: Sat, 11 Jul 2009 19:13:30 +0200 From: Chadda? Fouch? chaddai.fou...@gmail.com Subject: Re: [Haskell-beginners] List.sort To: Patrick LeBoutillier patrick.leboutill...@gmail.com Cc:
Beginners Digest, Vol 13, Issue 8
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: external sort (Keith Sheppard) 2. Re: external sort (Felipe Lessa) 3. Re: external sort (Chadda? Fouch?) 4. type class question from MReader #8 (MH) 5. Re: type class question from MReader #8 (Brandon S. Allbery KF8NH) 6. Re: type class question from MReader #8 (MH) 7. Recursive macros in hsc2hs (Maur??cio) 8. Re: Recursive macros in hsc2hs (Antoine Latter) 9. Re: Recursive macros in hsc2hs (Brandon S. Allbery KF8NH) -- Message: 1 Date: Sat, 11 Jul 2009 22:15:24 -0400 From: Keith Sheppard keiths...@gmail.com Subject: Re: [Haskell-beginners] external sort To: Felipe Lessa felipe.le...@gmail.com Cc: beginners@haskell.org Message-ID: 92e42b740907111915v6717d87biade02644f9072...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 Felipe, Thanks. I need to learn how to use hoogle better :-) All, I've just figured out why I'm leaking file handles so please ignore question 1 -Keith On Sat, Jul 11, 2009 at 9:59 PM, Felipe Lessafelipe.le...@gmail.com wrote: On Sat, Jul 11, 2009 at 08:40:10PM -0400, Keith Sheppard wrote: 2) I'm guessing there's a smarter way to do unwrapMonads? unwrapMonads is actually sequence :), see [1]. [1] http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Control-Monad.html#sequence -- Felipe. ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- keithsheppard.name -- Message: 2 Date: Sat, 11 Jul 2009 23:27:45 -0300 From: Felipe Lessa felipe.le...@gmail.com Subject: Re: [Haskell-beginners] external sort To: beginners@haskell.org Message-ID: 20090712022745.gc23...@kira.casa Content-Type: text/plain; charset=us-ascii On Sat, Jul 11, 2009 at 08:40:10PM -0400, Keith Sheppard wrote: 4) Is there any other wacky stuff in my code that I should change? I would probably write readBinFiles as readBinFiles :: [String] - IO [BS.ByteString] readBinFiles = mapM readB where readB file = openBinaryFile file ReadMode = BS.hGetContents You may also write pointless code ;) readBinFiles :: [String] - IO [BS.ByteString] readBinFiles = mapM_ $ flip (=) BS.hGetContents . flip openBinaryFile ReadMode Another way of improving your code is trying to write the functions in the order that one would read them (that is, bottom-up or top-down). In the start you seem to be following a top-down approach until you reach a referecen to bufferPartialSortsBy which is on the other side :). HTH, -- Felipe. -- Message: 3 Date: Sun, 12 Jul 2009 11:04:41 +0200 From: Chadda? Fouch? chaddai.fou...@gmail.com Subject: Re: [Haskell-beginners] external sort To: Felipe Lessa felipe.le...@gmail.com Cc: beginners@haskell.org Message-ID: e9350eaf0907120204i68b84f33v8a16c78bb8...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Sun, Jul 12, 2009 at 4:27 AM, Felipe Lessafelipe.le...@gmail.com wrote: On Sat, Jul 11, 2009 at 08:40:10PM -0400, Keith Sheppard wrote: 4) Is there any other wacky stuff in my code that I should change? I would probably write readBinFiles as readBinFiles :: [String] - IO [BS.ByteString] readBinFiles = mapM readB  where readB file = openBinaryFile file ReadMode = BS.hGetContents You may also write pointless code ;) readBinFiles :: [String] - IO [BS.ByteString] readBinFiles = mapM_ $ flip (=) BS.hGetContents . flip openBinaryFile ReadMode You can greatly improve that by using the kleisli composition operator : readBinFiles = mapM (BS.hGetContents = flip openBinaryFile ReadMode) But if this is lazy bytestrings, this will leak handles like crazy... A nice solution would be to use the safe-lazy-io package : it is easy to add a finalizer that will remove the file once hGetContents is finished (with System.IO.Lazy.Internal.finallyLI) and to read a list of files lazily without leaking handles (see System.IO.Lazy.concat). http://hackage.haskell.org/package/safe-lazy-io -- Jedaï -- Message: 4 Date: Mon, 13 Jul 2009 23:43:40 -0400 From: MH mha...@gmail.com Subject: [Haskell-beginners] type class question from MReader #8 To: beginners@haskell.org Message-ID: 648da0750907132043q47269e42kccdfb6ef2c53f...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 I am reading the article from Monad Reader issue #8 called
Beginners Digest, Vol 13, Issue 12
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Rank beginner question about debugging (Brent Yorgey) 2. Re: Double's (Brent Yorgey) 3. Re: Rank beginner question about debugging (Joe Fredette) 4. Re: Double's (Nicolas Pouillard) 5. Re: Double's (Felipe Lessa) 6. haskell problem (B1lal) 7. Re: haskell problem (Isaac Dupree) 8. Re: haskell problem (Felipe Lessa) 9. Re: haskell problem (Brent Yorgey) -- Message: 1 Date: Tue, 21 Jul 2009 22:43:30 -0400 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] Rank beginner question about debugging To: beginners@haskell.org Message-ID: 20090722024329.ga24...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Tue, Jul 21, 2009 at 09:26:19AM -0400, Ben Wise wrote: Folks, I'm a rank beginner in Haskell, and though Haskell seems like a great language to start using, I've got a serious concern about debugging. In about 15 years of Lisp experience, then 15 years of C++, I've gotten pretty accustomed to the idea of using a debugger with lots of pre- and post-conditions on functions, breakpoints, stack trace, and variable inspection -- even though it gets tricky with delayed evaluation, macros, etc. in Lisp! If you think it's tricky in Lisp, it's about ten times as tricky with a lazy language like Haskell! Using gdb with Haskell executables is pretty much useless since the generated code doesn't correspond to the Haskell code in any obvious ways. And it's really hard to make traditional debuggers since the ghc runtime model looks nothing like traditional ones. However, There IS a debugger built into most recent versions of ghci which lets you do some of these things -- have you taken a look at that? I've done quite a bit of programming using the sort of debuggers you describe myself---with C, C++, and Java in particular. And yet in all the Haskell coding I've done over the past few years---some of it quite significant---I've rarely missed those sorts of debuggers. I'm not quite sure I understand the reason why. Perhaps it's partly because Haskell lets you program on such a high level that there's less room for the sorts of titchy errors that debuggers are so good at helping you find. In any case, I wouldn't worry about it too much at this point if I were you, and if you really do find yourself wanting it, take a look at the ghci debugger. -Brent -- Message: 2 Date: Tue, 21 Jul 2009 22:45:29 -0400 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] Double's To: beginners@haskell.org Message-ID: 20090722024529.gb24...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Tue, Jul 21, 2009 at 08:51:05PM -0300, Felipe Lessa wrote: On Tue, Jul 21, 2009 at 07:10:40PM -0400, Thomas Friedrich wrote: I really should have thought about this, but I didn't. Note that Rational's are really really really slow, probably it would be better to spend some time reading Goldberg's paper[1]. [1] http://docs.sun.com/source/806-3568/ncg_goldberg.html Premature optimization is the sqrt of all evil. -Brent -- Message: 3 Date: Wed, 22 Jul 2009 01:09:42 -0400 From: Joe Fredette jfred...@gmail.com Subject: Re: [Haskell-beginners] Rank beginner question about debugging To: Brent Yorgey byor...@seas.upenn.edu Cc: beginners@haskell.org Message-ID: 4a669f16.3070...@gmail.com Content-Type: text/plain; charset=iso-8859-1 I, for one, have never found a need for a more traditional debugger in haskell. Most of my 'bugs' are more accurately described as 'behavior which I did not intend' rather than the more normal description of 'behavior which breaks things'. That is, Haskell programs (almost) always work if they type-check, however, they may work in a way you had not planned on. :) /Joe Brent Yorgey wrote: On Tue, Jul 21, 2009 at 09:26:19AM -0400, Ben Wise wrote: Folks, I'm a rank beginner in Haskell, and though Haskell seems like a great language to start using, I've got a serious concern about debugging. In about 15 years of Lisp experience, then 15 years of C++, I've gotten pretty accustomed to the idea of using a debugger with lots of pre- and post-conditions on functions, breakpoints, stack trace, and variable inspection -- even though it gets tricky with delayed evaluation, macros, etc. in Lisp! If you think it's tricky in Lisp, it's about
Beginners Digest, Vol 13, Issue 15
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Typeclasses and inheritance (Chadda? Fouch?) 2. Re: Typeclasses and inheritance (Patrick LeBoutillier) 3. Re: Typeclasses and inheritance (Isaac Dupree) 4. haskell variables - or not (Duke Normandin) 5. Re: haskell variables - or not (Thomas Friedrich) 6. Re: haskell variables - or not (Thomas Davie) 7. Re: haskell variables - or not (Kyle Murphy) 8. Count how often a menu has been selected (Bernhard Lehnert) -- Message: 1 Date: Fri, 24 Jul 2009 20:27:35 +0200 From: Chadda? Fouch? chaddai.fou...@gmail.com Subject: Re: [Haskell-beginners] Typeclasses and inheritance To: Patrick LeBoutillier patrick.leboutill...@gmail.com Cc: beginners@haskell.org Message-ID: e9350eaf0907241127kb3a257bt853d519c83e63...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Fri, Jul 24, 2009 at 6:16 PM, Patrick LeBoutillierpatrick.leboutill...@gmail.com wrote: In the declaration of the class IPAddr, is there any way to force that the IPHost and IPMask types are made up from the same IPBits type? Basically I would like the compiler to enforce that Word (Host a) and Word (Mask a) be the same type for a specific instance of IPAddr. Unfortunately, this has not been implemented yet (in 6.10), though it should be in a future version of GHC (pretty soon probably), you'll then be able to write : class (IPHost (Host a), IPMask (Mask a), Word (Host a) ~ Word (Mask a)) = IPAddr a where but for now you must content yourself with adding it to the function context : -- Takes an IPAddr and returns another one describing the network subnet :: (Word (Host a) ~ Word (Mask a)) = a - a subnet a = let m = mask a h = host a in makeIPAddr (fromBits $ (bits h) .. (bits m)) $ m Note that I didn't put a IPAddr context since in your code subnet is a method of this class (with a default implementation), if this wasn't your intention you should correct the indentation. -- Jedaï -- Message: 2 Date: Fri, 24 Jul 2009 15:03:34 -0400 From: Patrick LeBoutillier patrick.leboutill...@gmail.com Subject: Re: [Haskell-beginners] Typeclasses and inheritance To: Chadda? Fouch? chaddai.fou...@gmail.com Cc: beginners@haskell.org Message-ID: b217a64f0907241203t24ea9929l682fc226fee5...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 -- Takes an IPAddr and returns another one describing the network subnet :: (Word (Host a) ~ Word (Mask a)) = a - a subnet a = let m = mask a h = host a in makeIPAddr (fromBits $ (bits h) .. (bits m)) $ m Excellent! Note that I didn't put a IPAddr context since in your code subnet is a method of this class (with a default implementation), if this wasn't your intention you should correct the indentation. You are right, the context was not necessary. The function is in fact a default implementation. BTW: Does what I'm trying to do make any sense at all? Does anyone know of a better/simpler way to do this (i.e making most of these computations independant of the exact underlying type)? Anyways, thanks a lot for your help, Patrick -- Jedaï -- = Patrick LeBoutillier Rosemère, Québec, Canada -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090724/e814bf4d/attachment-0001.html -- Message: 3 Date: Fri, 24 Jul 2009 15:36:19 -0400 From: Isaac Dupree m...@isaac.cedarswampstudios.org Subject: Re: [Haskell-beginners] Typeclasses and inheritance To: Patrick LeBoutillier patrick.leboutill...@gmail.com Cc: beginners@haskell.org Message-ID: 4a6a0d33.10...@isaac.cedarswampstudios.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Patrick LeBoutillier wrote: BTW: Does what I'm trying to do make any sense at all? Does anyone know of a better/simpler way to do this (i.e making most of these computations independant of the exact underlying type)? Actually, I would try to mostly avoid typeclasses. If you want to change the representation sometime, that's still possible if you have abstraction! maybe like data IPAddr n = IPAddr n n where typically n would be Word32 or Word128(does that exist?), and a polymorphic function doing math on it might use a (Num n) = context. Actually you might sometimes need to know what kind
Beginners Digest, Vol 13, Issue 17
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Re: Count how often a menu has been selected (Felipe Lessa) 2. Re: Sidebar to variables (Dean Herington) 3. Question on monads and laziness (Lakshmi Narasimhan Vaikuntam) 4. Re: uses of random number generators (Heinrich Apfelmus) 5. Getting the Takusen example code to compile -failed import problem (Daniel Everett) 6. Re: Question on monads and laziness (Dean Herington) 7. RE: Getting the Takusen example code to compile -failed import problem (Bayley, Alistair) -- Message: 1 Date: Sat, 25 Jul 2009 22:52:24 -0300 From: Felipe Lessa felipe.le...@gmail.com Subject: Re: [Haskell-beginners] Re: Count how often a menu has been selected To: beginners@haskell.org Message-ID: 20090726015224.ga9...@kira.casa Content-Type: text/plain; charset=us-ascii On Sat, Jul 25, 2009 at 08:22:33PM +0200, Bernhard Lehnert wrote: this works great except for the print a part which I replaced by: b - readIORef a print b Woops, sorry :). Tip: most haskellers would prefer either readIORef a = print or print = readIORef a even if you are already in a 'do' block. -- Felipe. -- Message: 2 Date: Sat, 25 Jul 2009 21:53:29 -0400 From: Dean Herington heringtonla...@mindspring.com Subject: Re: [Haskell-beginners] Sidebar to variables To: Duke Normandin dukeofp...@ml1.net,Haskell Beginners Beginners@haskell.org Message-ID: a06240800c691674b3...@[192.168.1.100] Content-Type: text/plain; charset=us-ascii ; format=flowed At 7:42 AM -0600 7/25/09, Duke Normandin wrote: My recent questions concerning variables spawned this observation: I take it that programming a solution using a functional language like Haskell is really about linking a series of functions from which a solution is derived. It seems to me that this approach would naturally encourage the use of the bottom-up method of program development. I mean, breaking the task down to the smallest possible segments, and then writing a function for each segment. Refactoring the task until the smallest segments are achieved. Very much like what I learned about programming in Forth (they use the term words to mean function) Am I on the right track here, in my view of the Haskell approach to programming solutions? -- duke Yes, indeed. Haskell, like Forth but probably even more so, makes it easy and profitable to program small pieces that can be combined in ever-larger chunks. Dean -- Message: 3 Date: Sun, 26 Jul 2009 09:23:33 +0530 From: Lakshmi Narasimhan Vaikuntam lakshminaras2...@gmail.com Subject: [Haskell-beginners] Question on monads and laziness To: Beginners@haskell.org Message-ID: 3cca9ddb0907252053u26db814et2eead20254a0e...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 Hello I am studying Real World Haskell chapter 9. Here is a snippet of code data Info = Info { infoPath :: FilePath , infoPerms :: Maybe Permissions , infoSize :: Maybe Integer , infoModTime :: Maybe ClockTime } deriving (Eq, Ord, Show) getInfo :: FilePath - IO Info -- file: ch09/ControlledVisit.hs traverse order path = do names - getUsefulContents path contents - mapM getInfo (path : map (path /) names) liftM concat $ forM (order contents) $ \info - do if isDirectory info infoPath info /= path then traverse order (infoPath info) else return [info] getUsefulContents :: FilePath - IO [String] getUsefulContents path = do names - getDirectoryContents path return (filter (`notElem` [., ..]) names) isDirectory :: Info - Bool isDirectory = maybe False searchable . infoPerms When I read about IO in the previous chapter, I learnt that reading a file can be done lazily. Here my doubt is that whether the expression order contents would generate a list of directory contents (held in memory) for use in forM construct. Because in a subsequent para, I find this line. If we are traversing a directory containing 100,000 files of which we care about three, we'll allocate a 100,000-element list before we have a chance to trim it down to the three we really want Wouldn't laziness ensure that in the traverse function, when iterating over directory contents using the list generated by order contents, it will generate just one element at a time and then free the memory for that entry immediately since we are not using the
Beginners Digest, Vol 13, Issue 18
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Closure (Matthew J. Williams) 2. Q) Using Data.Binary to parse a packet (Yang, Chul-Woong) 3. Re: Q) Using Data.Binary to parse a packet (Bjoern Brandenburg) 4. Re: Q) Using Data.Binary to parse a packet (Brent Yorgey) 5. Re: Closure (Magnus Therning) 6. type class question from Ternary Trees (MH) 7. Re: Closure (Matthew J. Williams) 8. Re: Closure (Brent Yorgey) 9. Re: type class question from Ternary Trees (Chadda? Fouch?) 10. MonadRandom or Control.Monad.Random (Michael P Mossey) -- Message: 1 Date: Wed, 29 Jul 2009 02:02:40 +0100 From: Matthew J. Williams matthewjwillia...@googlemail.com Subject: [Haskell-beginners] Closure To: beginners@haskell.org Message-ID: 4a6f9f92.0a04d00a.37e5.8...@mx.google.com Content-Type: text/plain; charset=us-ascii; format=flowed Good morning What is a closure and, what purpose does it serve? Sincerely, MJW -- Message: 2 Date: Wed, 29 Jul 2009 09:19:39 +0900 From: Yang, Chul-Woong cwy...@aranetworks.com Subject: [Haskell-beginners] Q) Using Data.Binary to parse a packet To: beginners@haskell.org Message-ID: 4a6f959b.20...@aranetworks.com Content-Type: text/plain; charset=EUC-KR Dear Haskellers. I would like to build simple UDP server application. To parse a packet, I decide to use Data.Binary as followings: data Packet = Packet { foo :: Word16, bar :: Word16, baz :: Word32 } deriving (Show, Eq) instance Binary Packet where get = do foo - get :: Get Word16 bar - get :: Get Word16 baz - get :: Get Word32 return (Packet foo bar baz) -- omitting put because we're now just receiving only serveUDP port handlerfunc = withSocketsDo $ do ... procMessages sock where procMessages sock = do (msg, _, addr) - recvFrom sock 10240 handlerfunc addr msg procMessages sock myHandler addr msg = do putStrLn $ decode (Data.ByteString.Lazy.Char8.Pack msg) run = serveUDP 8080 myHandler But, running it and sending sample udp packet results in following exception. *Main run Loading package syb ... linking ... done. Loading package base-3.0.3.1 ... linking ... done. Loading package array-0.2.0.0 ... linking ... done. Loading package containers-0.2.0.1 ... linking ... done. Loading package bytestring-0.9.1.4 ... linking ... done. Loading package parsec-2.1.0.1 ... linking ... done. Loading package network-2.2.1 ... linking ... done. Loading package binary-0.5.0.1 ... linking ... done. *** Exception: too few bytes. Failed reading at byte position 9 *Main Why and what can I do for this? Thanks in advance. Chul-Woong Yang -- Message: 3 Date: Tue, 28 Jul 2009 19:44:00 -0700 From: Bjoern Brandenburg bbb@gmail.com Subject: Re: [Haskell-beginners] Q) Using Data.Binary to parse a packet To: Yang, Chul-Woong cwy...@aranetworks.com Cc: beginners@haskell.org Message-ID: 7ba288b20907281944m1e367041j653e633ba0cf9...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 2009/7/28 Yang, Chul-Woong cwy...@aranetworks.com: *** Exception: too few bytes. Failed reading at byte position 9 *Main Why and what can I do for this? Thanks in advance. The Get monad is complaining that you are trying to read more than 8 bytes from a buffer of length 8. Presumably you are sending packets of that size? If you want to handle such errors (and you should), you could either first test the length of the incoming message or use exception handling to catch the exception in myHandler. - Björn -- Message: 4 Date: Wed, 29 Jul 2009 00:26:32 -0400 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] Q) Using Data.Binary to parse a packet To: beginners@haskell.org Message-ID: 20090729042632.ga31...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Wed, Jul 29, 2009 at 09:19:39AM +0900, Yang, Chul-Woong wrote: data Packet = Packet { foo :: Word16, bar :: Word16, baz :: Word32 } deriving (Show, Eq) instance Binary Packet where get = do foo - get :: Get Word16 bar - get :: Get Word16 baz - get :: Get Word32 return (Packet foo bar baz) -- omitting put because we're now just receiving only By the way, I have nothing to contribute towards solving your actual problem, but I wanted to point out that you can write this Binary instance much more simply. First of all, you can just write instance Binary Packet where get = do
Beginners Digest, Vol 14, Issue 1
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: MonadRandom or Control.Monad.Random (Brandon S. Allbery KF8NH) 2. Re: MonadRandom or Control.Monad.Random (Brent Yorgey) 3. Re: MonadRandom or Control.Monad.Random (Michael P Mossey) 4. Re: MonadRandom or Control.Monad.Random (Brent Yorgey) 5. Re: MonadRandom or Control.Monad.Random (Michael Mossey) 6. Re: MonadRandom or Control.Monad.Random (Brent Yorgey) 7. type constructors (Michael P Mossey) 8. Re: type constructors (Jason Dusek) 9. Re: type constructors (Daniel Fischer) 10. Haskell OpenGL trouble (Matt f) -- Message: 1 Date: Thu, 30 Jul 2009 20:11:42 -0400 From: Brandon S. Allbery KF8NH allb...@ece.cmu.edu Subject: Re: [Haskell-beginners] MonadRandom or Control.Monad.Random To: Michael P Mossey m...@alumni.caltech.edu Cc: beginners@haskell.org Message-ID: b7afeae3-25b4-4308-a034-67116ce5b...@ece.cmu.edu Content-Type: text/plain; charset=us-ascii On Jul 30, 2009, at 20:04 , Michael P Mossey wrote: Where can I find MonadRandom or Control.Monad.Random to install? It doesn't seem to be a system library, I can't find it with cabal or Hoogle. Cabal should have found http://hackage.haskell.org/package/MonadRandom -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH -- next part -- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/beginners/attachments/20090730/1d009752/PGP-0001.bin -- Message: 2 Date: Thu, 30 Jul 2009 22:33:21 -0400 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] MonadRandom or Control.Monad.Random To: beginners@haskell.org Message-ID: 20090731023321.ga16...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Thu, Jul 30, 2009 at 05:04:54PM -0700, Michael P Mossey wrote: Where can I find MonadRandom or Control.Monad.Random to install? It doesn't seem to be a system library, I can't find it with cabal or Hoogle. 'cabal install MonadRandom' ought to work. Note that you may have to 'cabal update' first to make sure cabal has the most up-to-date package list. You can also always look at the complete list of packages on Hackage by going to hackage.haskell.org. -Brent -- Message: 3 Date: Fri, 31 Jul 2009 17:55:43 -0700 From: Michael P Mossey m...@alumni.caltech.edu Subject: Re: [Haskell-beginners] MonadRandom or Control.Monad.Random To: beginners beginners@haskell.org Message-ID: 4a73928f.4050...@alumni.caltech.edu Content-Type: text/plain; charset=ISO-8859-1; format=flowed Brent Yorgey wrote: On Thu, Jul 30, 2009 at 05:04:54PM -0700, Michael P Mossey wrote: Where can I find MonadRandom or Control.Monad.Random to install? It doesn't seem to be a system library, I can't find it with cabal or Hoogle. 'cabal install MonadRandom' ought to work. Note that you may have to 'cabal update' first to make sure cabal has the most up-to-date package list. You can also always look at the complete list of packages on Hackage by going to hackage.haskell.org. -Brent ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners That worked. I'm looking at this example from the docs. I understand most of this but I can't find a definition of getRandomR. See die has type (Rand g Int) I'm assuming getRandomR is a function that has that type, but I can't find its definition. import Control.Monad.Random die :: (RandomGen g) = Rand g Int die = getRandomR (1,6) dice :: (RandomGen g) = Int - Rand g [Int] dice n = sequence (replicate n die) main = do values - evalRandIO (dice 2) putStrLn (show values) -- Message: 4 Date: Fri, 31 Jul 2009 21:02:02 -0400 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] MonadRandom or Control.Monad.Random To: beginners@haskell.org Message-ID: 20090801010202.ga22...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Fri, Jul 31, 2009 at 05:55:43PM -0700, Michael P Mossey wrote: Brent Yorgey wrote: On Thu, Jul 30, 2009 at 05:04:54PM -0700, Michael P Mossey
Beginners Digest, Vol 14, Issue 8
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: function parameter types after flip (Daniel Fischer) 2. Re: some terminology (Maur??cio CA) 3. Re: Closure (Daniel Bastos) 4. monad transformers (Michael P Mossey) 5. Constructors as functions (was monad transformers) (Michael P Mossey) 6. Re: monad transformers (Brandon S. Allbery KF8NH) 7. Re: Constructors as functions (was monad transformers) (Isaac Dupree) 8. Re: Closure (Heinrich Apfelmus) 9. Circular programming (Maciej Piechotka) 10. Re: Circular programming (Peter Verswyvelen) -- Message: 1 Date: Thu, 13 Aug 2009 17:52:58 +0200 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] function parameter types after flip To: beginners@haskell.org Message-ID: 200908131752.58655.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-1 Am Donnerstag 13 August 2009 17:25:07 schrieb Robert Ziemba: Can anyone help me understand the behavior of the following expressions in ghci? I was trying to construct a flipped function 'elem' that would accept a list of characters first but I ran into this problem with the type signature. Thank you. Prelude Data.List Data.Char :t elem elem :: (Eq a) = a - [a] - Bool -- OK Prelude Data.List Data.Char :t (flip elem) (flip elem) :: (Eq a) = [a] - a - Bool -- OK this is what I want Prelude Data.List Data.Char let fElem = (flip elem) Prelude Data.List Data.Char :t fElem fElem :: [()] - () - Bool -- ?? Function will not accept a [Char] It's the monomorphism restriction. If you bind a name by a simple pattern binding (like [let] fElem = flip elem) and don't give a type signature, it must have a monomorphic type and in ghci, that defaults to () for unconstrained type variables. Ways to fix the behaviour: 1. give an explicit type signature (good in code files anyway, but cumbersome at the ghci prompt) 2. make it a function binding: let fElem xs x = x `elem` xs let fElem xs = (`elem` xs) let fElem xs = flip elem xs 3. run ghci without the monomorphism restriction Prelude :set -XNoMonomorphismRestriction Prelude let fElem = flip elem Prelude :t fElem fElem :: (Eq a) = [a] - a - Bool (that would be a good entry in your .ghci file anyway, you rarely want it unless you are a compiler writer) -- Message: 2 Date: Thu, 13 Aug 2009 14:34:12 -0300 From: Maur??cio CA mauricio.antu...@gmail.com Subject: [Haskell-beginners] Re: some terminology To: beginners@haskell.org Message-ID: h61iqk$cq...@ger.gmane.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed I was looking at some code, saw a variable x, and said to myself, Ah that variable is a monad. Then I realized Monad is the name of a type class. So maybe x should be called an instance of a Monad. I think the word instance in this case is OO-like; but in Haskell instance refers to a type that is an instance of a type class. [...] In general, it helps to know that the current de facto Haskell standard actually accepts classes and instances built on top of many types: class SomeClass a b c where someF :: a - b - c anotherF :: b - c - a instance SomeClass T1 T2 T3 where someF = ... anotherF = ... This way it becomes clear that saying that some type is of or instantiate some class isn't apropriate. Best, Maurício -- Message: 3 Date: Fri, 14 Aug 2009 23:46:02 + (UTC) From: Daniel Bastos dbasto...@toledo.com Subject: [Haskell-beginners] Re: Closure To: beginners@haskell.org Message-ID: h64svq$ck...@ger.gmane.org In article h5tjgk$6d...@ger.gmane.org, Daniel Bastos wrote: In article 20090729202442.ga8...@seas.upenn.edu, Brent Yorgey wrote: With that said, on some level the idea of a closure is really just an implementation detail---I wouldn't say that understanding it is of fundamental importance in learning Haskell. But learning things never hurts (except when it does). So it sounds correct to say that a closure is a function that brings an environment with it, such as variables defined outside of it. With this ability, we can construct functions on the fly because a function can return a closure which is amended and, say, returned again another closure more fully specified. Hello. This was actually a request for comments. Though I didn't say it. Does that sound correct?
Beginners Digest, Vol 14, Issue 9
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Circular programming (Peter Verswyvelen) 2. learning to use Haskell types (Michael Mossey) 3. Re: Closure (Daniel Bastos) 4. Re: Re: Closure (Daniel Fischer) 5. Re: Re: Closure (Brandon S. Allbery KF8NH) 6. Re: Closure (Daniel Bastos) 7. Re: Closure (Daniel Bastos) 8. Re: Re: Closure (Daniel Fischer) 9. List combination function? (Ian Duncan) -- Message: 1 Date: Sat, 15 Aug 2009 14:27:54 +0200 From: Peter Verswyvelen bugf...@gmail.com Subject: Re: [Haskell-beginners] Circular programming To: Maciej Piechotka uzytkown...@gmail.com Cc: beginners@haskell.org Message-ID: a88790d10908150527s2ef5f9bdw54f7d7c2dcfc...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 oh and reading first about fix should help too: http://en.wikibooks.org/wiki/Haskell/Fix_and_recursion http://en.wikibooks.org/wiki/Haskell/Fix_and_recursion On Sat, Aug 15, 2009 at 1:43 PM, Peter Verswyvelen bugf...@gmail.comwrote: It might help to read the Yampa Arcadehttp://haskell.cs.yale.edu/yale/papers/haskell-workshop03/yampa-arcade.pdfand then Plugging a Space Leak with an Arrowhttp://cs-www.cs.yale.edu/homes/hl293/download/leak.pdfto get a practical example of circuit and circular programming. On Sat, Aug 15, 2009 at 11:16 AM, Maciej Piechotka uzytkown...@gmail.comwrote: I'm not understending circular programming. What it is used for? Where feedback variable came from (yes - I know it's wrong question as Haskell is lazy)? I've read http://www.haskell.org/haskellwiki/Circular_programming but I didn't understend the concept and pattern. Regards ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090815/f922ad19/attachment-0001.html -- Message: 2 Date: Sat, 15 Aug 2009 07:36:46 -0700 From: Michael Mossey m...@alumni.caltech.edu Subject: [Haskell-beginners] learning to use Haskell types To: beginners beginners@haskell.org Message-ID: 4a86c7fe.2080...@alumni.caltech.edu Content-Type: text/plain; charset=ISO-8859-1; format=flowed This is really a general question, but any advice is welcome. I'm currently working through Typeclassopedia and all the tutorials it links to. I'm really enjoying it, but a kind of scary question is: when I begin to write real software in Haskell, how will I find natural places to use the types and how will I make the transition to idiomatic Haskell? [Note: the main application I have for Haskell is my music composition hobby. I plan to use Haskell to write software for editing music and for computer-assisted composition (CAC). CAC means the computer does some of the tedious work involved in searching for, and evaluation of, combinations of musical themes. All my algorithms are personal to my own process. There is no off-the-shelf software that can help me. That's why it's fortunate I'm a programmer. The CAC features need to be tightly integrated into a musical score editor, hence I have to write that too. Really quite a fun project, and even if it takes two years, I will get years and years of enjoyment from it!] Then it occurred to me that a common theme in Haskell is to provide a way to express a solution to a problem in an expressive form that is natural to that problem. So maybe what I need to do is stop thinking, Where can I use this type, and instead dream up ways to express ideas in a simple and natural form, then make use of Haskell types and type classes to make that expressive form a reality. For example, in a music editor, there are many actions that create new notes. A note needs many pieces of information to describe it: the note's place in time, its duration, dynamics, whether tied to successive notes, type of flag or beam... Much of this information can be inferred from the context in which the note is created, and so a natural expressive language would bring a new note into existence with a minimal need for providing details. Those details would be inferred from the context. So that's a Reader monad right there. Thanks, Mike -- Message: 3 Date: Sat, 15 Aug 2009 16:07:08 + (UTC) From: Daniel Bastos dbasto...@toledo.com Subject:
Beginners Digest, Vol 14, Issue 12
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Ambigous Types with Haskell Functional Graph Library (Christian Maeder) 2. Re: my ugly code and the Maybe monad (Simon Parry) 3. Re: my ugly code and the Maybe monad (Jan Jakubuv) 4. type inference question (I. J. Kennedy) 5. Re: type inference question (Daniel Fischer) 6. definition of combinator (Michael Mossey) 7. Re: definition of combinator (Brandon S. Allbery KF8NH) 8. Re: definition of combinator (Jan Jakubuv) -- Message: 1 Date: Wed, 19 Aug 2009 17:16:41 +0200 From: Christian Maeder christian.mae...@dfki.de Subject: [Haskell-beginners] Re: Ambigous Types with Haskell Functional GraphLibrary To: Joe Schafer joesmo...@gmail.com Cc: beginners@haskell.org Message-ID: 4a8c1759.5020...@dfki.de Content-Type: text/plain; charset=ISO-8859-1 The type constructor variable gr can be instantiated with Data.Graph.Inductive.Tree.Gr via a type signature: Prelude Data.Graph.Inductive.Example ucycle 5 :: Data.Graph.Inductive.Tree.Gr () () 1:()-[((),2)] 2:()-[((),3)] 3:()-[((),4)] 4:()-[((),5)] 5:()-[((),1)] HTH Christian Joe Schafer wrote: Hey all, New to Haskell and I'm trying to use the FGL but I keep running into the same error. If I load Data.Graph.Inductive.Example and use one of the example functions such as ucycle I get: Ambiguous type variable `gr' in the constraint: `Graph gr' arising from a use of `ucycle' at interactive:1:0-7 Probable fix: add a type signature that fixes these type variable(s) Here's the type of ucycle for reference. ucycle :: Graph gr = Int - gr () () I'm using GHC 6.10.1 and FGL 5.4.2.2 Thanks, Joe -- Message: 2 Date: Wed, 19 Aug 2009 23:57:47 +0100 From: Simon Parry sparr...@googlemail.com Subject: Re: [Haskell-beginners] my ugly code and the Maybe monad To: Jan Jakubuv jaku...@gmail.com, ; beginners@haskell.org Message-ID: 1250722667.2431.65.ca...@localhost.localdomain Content-Type: text/plain; charset=UTF-8 Thanks Jan, very helpful and you're right I am just trying to combine 2 lists; one with 'wrapped' values, one without. You can write your own version of `liftM2` (from `Control.Monad`) like this: liftM2snd f a mb = do { b - mb; return (f a b) } so the b - mb bit is 'unwrapping' the Maybe b to use it with the pure function f? I guess I didn't realise this as I've only seen it in the IO monad, but naturally it would work with all monads. You can verify that liftM2snd == (fmap .) if I look at this in GHCi the liftM2snd acts over monads and the (fmap .) acts over functors. Now I'm still trying to get comfortable with simple monad manipulations so maybe I should just read this as functors are equivalent to monads and not worry too much about it yet? With that in mind fmap acts to map some pure function over a 'wrapped' value? Thanks also for the other suggestions, its always helpful to see a progression rather than jumping in at say pvs5. Anyway, note that all the `pvs` functions (including the your one) return `Nothing` when `(df yield)` returns `Nothing` for at least one related member of `times`. Is that what you want? I did want it to only perform the calc if the yield was sensible. thanks again Simon On Wed, 2009-08-19 at 12:53 +0100, Jan Jakubuv wrote: Hi Simon, On Tue, Aug 18, 2009 at 10:41:45PM +0100, Simon Parry wrote: It seems to work ok (I haven't properly tested it yet) but I feel the pvs function is just ugly. However it seems like its a fairly common requirement for maths modelling ie using Maybe or Error or such to represent conditions on the input variables and then later having to combine those 'wrapped' values with other things. I don't quite understand what is function `pvs` supposed to do ?? Anyway, I try to guess. It seems that it just applies `(df yield)` to `times` and then multiply the resulting values one by one with `cashflow`. So it seems that you need to lift multiplication `(*)` to the Maybe monad in the second argument only. You can write your own version of `liftM2` (from `Control.Monad`) like this: liftM2snd f a mb = do { b - mb; return (f a b) } You can verify that liftM2snd == (fmap .) Thus you can rewrite `pvs` as: pvs2 df yield cashflow = multiply cashflow discounts where multiply = zipWithM (fmap . (*)) discounts = map (df yield)
Beginners Digest, Vol 15, Issue 1
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. haskell code to html (I. J. Kennedy) 2. Re: haskell code to html (Daniel Fischer) 3. Figuring out errors (Edward Z. Yang) 4. Re: Utter Newbie - simple problems, output - GHC vs GHCi (Magnus Therning) 5. Using FiniteMap in ghci (KwangYul Seo) 6. Re: Using FiniteMap in ghci (Chadda? Fouch?) 7. Re: Using FiniteMap in ghci (KwangYul Seo) 8. Re: Using FiniteMap in ghci (Daniel Fischer) 9. function - argument termination problem (??? ) 10. Re: function - argument termination problem (Rahul Kapoor) 11. Re: function - argument termination problem (Magnus Therning) -- Message: 1 Date: Mon, 31 Aug 2009 21:08:01 -0500 From: I. J. Kennedy j...@realmode.com Subject: [Haskell-beginners] haskell code to html To: beginners@haskell.org Message-ID: 1008bfc90908311908n12e1ef5ai83ad93caa5eea...@mail.gmail.com Content-Type: text/plain; charset=utf-8 Is there a decent utility out there for syntax coloring haskell code?(haskell to html) -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090831/9e81a648/attachment-0001.html -- Message: 2 Date: Tue, 1 Sep 2009 04:18:44 +0200 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] haskell code to html To: beginners@haskell.org Message-ID: 200909010418.45026.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-15 Am Dienstag 01 September 2009 04:08:01 schrieb I. J. Kennedy: Is there a decent utility out there for syntax coloring haskell code?(haskell to html) HsColour: http://hackage.haskell.org/package/hscolour cabal update cabal install hscolour if you have a working cabal binary (if you haven't, you should get yourself one) -- Message: 3 Date: Mon, 31 Aug 2009 23:02:10 -0400 From: Edward Z. Yang ezy...@mit.edu Subject: [Haskell-beginners] Figuring out errors To: beginners beginners@haskell.org Message-ID: 1251773361-sup-1...@javelin Content-Type: text/plain; charset=UTF-8 Hello all, I've been looking at [1] and trying to make tops and bottoms (pardon the pun) of error handling in Haskell. I am still uncertain of what to do. I recognize that there are different areas of code that may have different requirements for errors: * Pure code that is simple enough can probably get away with returning Maybe a * Pure code that has multiple failure modes (the canonical example is parsing) should return a Either e a. The type of e is a little difficult: many standard libraries seem to use String, but coming from Python this seems analogous to the long deprecated string exceptions, which are quick and easy but not long-term maintainable due to lack of an easy way to match for them. This leads naturally into Either MyError, which is supported using throwError and catchError. * However, [1] specifically warns against using this technique in the IO monad, and I need a way to short circuit execution when a crucial pure operation fails (in Python, this would have just been an uncaught exception). This suggests using ErrorT on IO, however, [1] also claims that this is generally not a good idea, and suggests to use throwDyn (which actually looks like it's been renamed to throw) * Unfortunately, when I've tried to use this technique, I've run up against the fact that throw is implemented using bottom, so if I do a throw in a pure function, the exception might not actually surface up until I'm, say, attempting to print its return value to IO. Denizens on #haskell have instructed me to treat bottom as the bane of existence and opt for stacking ErrorT on IO (it would be nice to know if this was a good idea or bad idea) At which point, I am most thoroughly confused. Pointers, please! Cheers, Edward [1] http://www.randomhacks.net/articles/2007/03/10/haskell-8-ways-to-report-errors -- Message: 4 Date: Wed, 2 Sep 2009 07:39:34 +0200 From: Magnus Therning mag...@therning.org Subject: Re: [Haskell-beginners] Utter Newbie - simple problems, output - GHCvs GHCi To: Nigel Rantor wig...@wiggly.org Cc: beginners@haskell.org Message-ID: e040b520909012239t7f64b69fia83e1926f8eab...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Mon, Aug 31, 2009 at 12:32 AM,
Beginners Digest, Vol 15, Issue 3
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Help with CSV (Keith Sheppard) 2. Re: Identical function and variable names andtype inference (Magnus Therning) 3. Re: Identical function and variable names andtype inference (Magnus Therning) 4. Multiplexing I/O in Haskell (Sergey V. Mikhanov) 5. Re: Multiplexing I/O in Haskell (Magnus Therning) 6. Haskell data structures: cheap immutable manipulation and nested equality? (Anand Patil) 7. Re: Haskell data structures: cheap immutable manipulation and nested equality? (Heinrich Apfelmus) 8. Generalised data constructor matching (Colin Campbell-McPherson) 9. Re: Generalised data constructor matching (Daniel Fischer) -- Message: 1 Date: Wed, 2 Sep 2009 21:23:05 -0400 From: Keith Sheppard keiths...@gmail.com Subject: Re: [Haskell-beginners] Help with CSV To: Hong Yang hyang...@gmail.com, beginners@haskell.org Message-ID: 92e42b740909021823x6e32cf56o8138e2b8339da...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 Not quite code but... here is an example of parsing CSV http://book.realworldhaskell.org/read/using-parsec.html and here is a library that you can use which is similar http://hackage.haskell.org/package/csv These approaches give you a 2D String list that you can do whatever you want with. if you need to turn a string into a double and you know the string is well formed i think the syntax looks like let doubleVal = read stringVal :: Double There are better ways to do this if you need to be able to handle formatting errors but I don't know them off the top of my head -Keith On Wed, Sep 2, 2009 at 6:40 PM, Hong Yanghyang...@gmail.com wrote: I need to process csv files that have the characteristics as follows: 1) each file has thousands of columns which have String, Int, and Double types 2) the number of columns may change 3) for those columns whose name do not change, their location may change I want to process some columns in 3) using Haskell. In Perl, I can easily have the code like below: use Text::CSV; my $csv = Text::CSV-new( { allow_whitespace = 1 } ); open my $temp, , temp.csv or die Cannot open temp.csv! ($!); my @fields = @{ $csv-getline($temp) }; $csv-column_names(@fields); while ( my $hr = $csv-getline_hr($temp) ) { my $sn = $hr-{UNIT:unitSerialNumber}; # processing goes here ... } close $temp; Can someone please give me an equivalent code in Haskell? Then I can digest and expand it. Thanks, Hong ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- keithsheppard.name -- Message: 2 Date: Thu, 3 Sep 2009 08:35:56 +0200 From: Magnus Therning mag...@therning.org Subject: Re: [Haskell-beginners] Identical function and variable names and type inference To: Thomas Davie tom.da...@gmail.com Cc: beginners beginners@haskell.org Message-ID: e040b520909022335t28c49faaya3190d93776fa...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Wed, Sep 2, 2009 at 11:33 PM, Thomas Davietom.da...@gmail.com wrote: Ints can't make up the function part of an application, that must have type (a - b). Well, I don't think that's strictly true. foo::Int can be argued to be a function that takes no arguments and return an Int. It is however very convenient to call such a function a constant. However, that such a function actully is constant is far from guaranteed in most programming languages. It happens to be true in Haskell though, due to the strict separation between (proper) functions and procedures (functions with side effects, i.e. stuff in the IO monad). In the mean time, the reason it didn't accept test id = id id is because it must fix the argument id to only one type. It infers that id must have type (a - b), from the fact that it appears in the function position, then sees it in the argument position, and infers that a = (a - b) which obviously causes a problem. Â To resolve that problem, you need rank-2 polymorphism. Is that really correct? I suspect the only thing that causes the OP problems is scoping. If I understand you correctly I wouldn't be able to do the following: Prelude let f x = x Prelude :t f f :: t - t Prelude :t id id :: a - a Prelude :t id f id f :: t - t Prelude let g = id f Prelude :t g g :: t - t Prelude id 5 5
Beginners Digest, Vol 15, Issue 4
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Generalised data constructor matching (Chadda? Fouch?) 2. Re: Generalised data constructor matching (Daniel Fischer) 3. Re: Haskell data structures: cheap immutable manipulation and nested equality? (Heinrich Apfelmus) 4. graphics.ui.wxcore (John Moore) 5. Re: graphics.ui.wxcore (Daniel Fischer) 6. Urgent: Defining Momory data Types in Haskell (Akshay Dave) 7. Re: Urgent: Defining Momory data Types in Haskell (Peter Verswyvelen) 8. RE: Urgent: Defining Momory data Types in Haskell (Akshay Dave) -- Message: 1 Date: Sat, 5 Sep 2009 09:53:34 +0200 From: Chadda? Fouch? chaddai.fou...@gmail.com Subject: Re: [Haskell-beginners] Generalised data constructor matching To: Daniel Fischer daniel.is.fisc...@web.de Cc: beginners@haskell.org Message-ID: e9350eaf0909050053y72016542w2748488566794...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Fri, Sep 4, 2009 at 2:57 PM, Daniel Fischerdaniel.is.fisc...@web.de wrote: In general: not. The problem is that potentially every datatype can be made an instance of the class, so in the default implementations, you can only[*] use functions which work on every datatype. There aren't many interesting functions that do. [*]well, you can also use methods of the class and superclasses. And so by using Data and Typeable as superclasses, he could do what he is asking for... And Data and Typeable are automatically derivables by GHC (extension). -- Jedaï -- Message: 2 Date: Sat, 5 Sep 2009 14:45:25 +0200 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] Generalised data constructor matching To: Chadda? Fouch? chaddai.fou...@gmail.com Cc: beginners@haskell.org Message-ID: 200909051445.25550.daniel.is.fisc...@web.de Content-Type: text/plain; charset=utf-8 Am Samstag 05 September 2009 09:53:34 schrieb Chaddaï Fouché: On Fri, Sep 4, 2009 at 2:57 PM, Daniel Fischerdaniel.is.fisc...@web.de wrote: In general: not. The problem is that potentially every datatype can be made an instance of the class, so in the default implementations, you can only[*] use functions which work on every datatype. There aren't many interesting functions that do. [*]well, you can also use methods of the class and superclasses. And so by using Data and Typeable as superclasses, he could do what he is asking for... And Data and Typeable are automatically derivables by GHC (extension). True. But I don't think the code would become any shorter/better/easier to maintain (*shudder*), so I'd stick to individual instance declarations. -- Message: 3 Date: Sun, 06 Sep 2009 17:07:19 +0200 From: Heinrich Apfelmus apfel...@quantentunnel.de Subject: [Haskell-beginners] Re: Haskell data structures: cheap immutable manipulation and nested equality? To: beginners@haskell.org Message-ID: h80j7a$k9...@ger.gmane.org Content-Type: text/plain; charset=ISO-8859-1 Anand Patil wrote: Heinrich Apfelmus wrote: Anand Patil wrote: - Cheap equality by value: user= (= m {:a 1 :b 2 :c {:d 3 :f 4}}) false user= (= m {:a 1 :b 2}) true If I understand correctly, equality is computed based on some kind of hash rather than by comparing the two maps element by element, so it's efficient even for large and/or nested collections. Why would you need this feature? I can only think of common subexpression elimination. I have an expensive function that takes complicated data structures as an argument, and I know that it will often be evaluated twice running with the same argument, but it will be evaluated with lots of different arguments over the course of the program. A cheap equality test would make it easy to cache the last return value. Is there a better way to optimize this in Haskell? Sounds indeed like a case for memoization to me. (While complicated data structures as keys sounds suspicious, in my opinion.) Cheap equality won't necessarily help, though, you want at least the hash value itself. But since calculating a hash will take O(length of complicated data structure) anyway, you can also use a memoization scheme based on sums of products which has the same complexity^1. In particular, have a look at http://hackage.haskell.org/package/data-memocombinators which is used like this: fib = Memo.integral fib' where fib' 0 = 0 fib' 1
Beginners Digest, Vol 15, Issue 5
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. number formatting with locale (Dmitry Simonchik) 2. idiomatic haskell question (Tom Doris) 3. qtHaskell, ForeignPtr (Michael Mossey) 4. oops (Michael Mossey) 5. Re: oops (Peter Verswyvelen) 6. Re: qtHaskell, ForeignPtr (Daniel Fischer) 7. Re: idiomatic haskell question (Andrew Wagner) -- Message: 1 Date: Mon, 7 Sep 2009 13:05:39 +0400 From: Dmitry Simonchik d...@simonchik.net Subject: [Haskell-beginners] number formatting with locale To: beginners@haskell.org Message-ID: 80eb7b2e0909070205t649e6c01y648ae9756a42e...@mail.gmail.com Content-Type: text/plain; charset=utf-8 Hi all haskell lovers I'm trying to print out Double in russian locale (we use , as decimal separator insetad of .). I'm trying to set locale with System.Locale.SetLocale like setLocale LC_ALL $ Just ru_RU.UTF-8 this returns Just ru_RU.UTF-8, so it seems that function call succeeded, but when I call show 20.2 it just prints 20.2 and not desired 20,2 Can anyone please help? -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090907/edd802be/attachment-0001.html -- Message: 2 Date: Mon, 7 Sep 2009 18:28:22 +0100 From: Tom Doris tomdo...@gmail.com Subject: [Haskell-beginners] idiomatic haskell question To: beginners@haskell.org Message-ID: 19e5d1d00909071028s349a7552tae8036f3b1567...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 Hi all, I've recently started using Haskell and am looking for some feedback on code I've written; I sometimes feel that maybe I'm not doing things the best way possible that Haskell allows, and maybe missing out on obvious improvements in brevity or elegance. So here's a tic-tac-toe solver I wrote that does basic min-max search of the entire tree (not efficient algorithmically, but it's tictactoe so a blank board can be fully solved in a few seconds). Also, if people have suggestions on how to change the program to actually output the moves it would make, please let me know - right now it just responds with 1 for a win for X, 0 for a draw, and -1 for a win for O. And there are probably bugs! Thanks in advance import Data.List data Box = Blank | X | O deriving (Eq, Show) -- usage: call score with the board rows concatenated: score [Blank, Blank, Blank, Blank, Blank, Blank, Blank, Blank, Blank] -- or score [Blank, X, O, Blank, X, O, Blank, Blank, Blank] -- score is 1 if X wins, 0 for draw, -1 for lose score :: [Box] - Int score g | haveline X g = 1 | haveline O g = -1 | gridfull g = 0 | isxmove g = maximum (map score (makeallmoves X g)) | otherwise = minimum (map score (makeallmoves O g)) tolines :: [Box] - [[Box]] tolines [a1, a2, a3, b1, b2, b3, c1, c2, c3] = [ [a1,a2,a3], [b1,b2,b3], [c1,c2,c3], [a1,b1,c1], [a2,b2,c2], [a3,b3,c3], [a1,b2,c3], [a3,b2,c1] ] haveline :: Box-[Box] - Bool haveline b g = any ([b,b,b]==) (tolines g) gridfull :: [Box] - Bool gridfull g = not $ any (Blank==) g isxmove :: [Box] - Bool isxmove g = let movecount = sum $ map (\b - if b==Blank then 0 else 1) g in mod movecount 2 == 0 isomove = not . isxmove fl :: Box-[Box]-[Box]-[[Box]] fl b xs (Blank:ys) = [xs ++ b:ys] fl _ _ _ = [] makeallmoves :: Box-[Box]- [[Box]] makeallmoves b g = concat $ zipWith (fl b) (inits g) (tails g) -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090907/9a7ec5f1/attachment-0001.html -- Message: 3 Date: Mon, 7 Sep 2009 14:54:17 -0700 (PDT) From: Michael Mossey m...@alumni.caltech.edu Subject: [Haskell-beginners] qtHaskell, ForeignPtr To: beginners@haskell.org Message-ID: 64711.208.57.251.240.1252360457.squir...@mail.alumni.caltech.edu Content-Type: text/plain;charset=iso-8859-1 I'm trying to learn qtHaskell, an interface to the Qt GUI library. I am fairly new to Haskell, but have used Qt for a long time, so I thought I could probably reasonably attempt to grok qtHaskell at this point. My main question is: anyone recommended a good explanation of the foreign function or foreign pointer interface? My immediate question is that I was poking through the Qtc docs, and saw this: Documentation
Beginners Digest, Vol 15, Issue 6
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Help with CSV (Hong Yang) 2. Re: Help with CSV (Erik de Castro Lopo) 3. Re: number formatting with locale (Heinrich Apfelmus) 4. Re: Re: number formatting with locale (Dmitry Simonchik) 5. Re: Urgent: Defining Momory data Types in Haskell (Brent Yorgey) 6. Re: Re: number formatting with locale (Wirt Wolff) 7. Problems defining a type with a multiplication function (Amy de Buitl?ir) 8. Re: Problems defining a type with a multiplication function (John Dorsey) -- Message: 1 Date: Mon, 7 Sep 2009 21:35:29 -0500 From: Hong Yang hyang...@gmail.com Subject: Re: [Haskell-beginners] Help with CSV To: Keith Sheppard keiths...@gmail.com Cc: beginners@haskell.org Message-ID: f31db34d0909071935m5b86f670xb8beb64d5cc10...@mail.gmail.com Content-Type: text/plain; charset=utf-8 Thanks for your reply. I have a working program now using Text.CSV module. Do you see any that can be improved? When I print, the screen reads Just abc. How can I get rid of Just in the most elegant way? Thanks, Hong -- file: ch22/PodMain.hs module Main where import System.Environment (getArgs) import Text.CSV import qualified Data.Map as M main = do [args] - getArgs result - parseCSVFromFile args case result of Left errmsg- putStrLn Error when parsing! Right contents - map_header_records contents map_header_records :: CSV - IO () map_header_records [] = return () map_header_records (x:xs) = process x xs process :: [String] - CSV - IO () process x [] = return () process x (y:ys) = do let tuple = zip x y let hash = M.fromList tuple putStrLn (show (M.lookup name hash)) process x ys On Wed, Sep 2, 2009 at 8:23 PM, Keith Sheppard keiths...@gmail.com wrote: Not quite code but... here is an example of parsing CSV http://book.realworldhaskell.org/read/using-parsec.html and here is a library that you can use which is similar http://hackage.haskell.org/package/csv These approaches give you a 2D String list that you can do whatever you want with. if you need to turn a string into a double and you know the string is well formed i think the syntax looks like let doubleVal = read stringVal :: Double There are better ways to do this if you need to be able to handle formatting errors but I don't know them off the top of my head -Keith On Wed, Sep 2, 2009 at 6:40 PM, Hong Yanghyang...@gmail.com wrote: I need to process csv files that have the characteristics as follows: 1)each file has thousands of columns which have String, Int, and Double types 2)the number of columns may change 3)for those columns whose name do not change, their location may change I want to process some columns in 3) using Haskell. In Perl, I can easily have the code like below: use Text::CSV; my $csv = Text::CSV-new( { allow_whitespace = 1 } ); open my $temp, , temp.csv or die Cannot open temp.csv! ($!); my @fields = @{ $csv-getline($temp) }; $csv-column_names(@fields); while ( my $hr = $csv-getline_hr($temp) ) { my $sn = $hr-{UNIT:unitSerialNumber}; # processing goes here ... } close $temp; Can someone please give me an equivalent code in Haskell? Then I can digest and expand it. Thanks, Hong ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- keithsheppard.name -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090907/971883c0/attachment-0001.html -- Message: 2 Date: Tue, 8 Sep 2009 12:45:30 +1000 From: Erik de Castro Lopo mle...@mega-nerd.com Subject: Re: [Haskell-beginners] Help with CSV To: beginners@haskell.org Message-ID: 20090908124530.6e280a53.mle...@mega-nerd.com Content-Type: text/plain; charset=US-ASCII Hong Yang wrote: Thanks for your reply. I have a working program now using Text.CSV module. Do you see any that can be improved? When I print, the screen reads Just abc. How can I get rid of Just in the most elegant way? Try Data.Maybe.fromMaybe: http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:fromMaybe Erik -- -- Erik de Castro Lopo
Beginners Digest, Vol 15, Issue 7
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Problems defining a type with a multiplication function (Joe Fredette) 2. Re: Problems defining a type with a multiplication function (John Dorsey) 3. Re: Problems defining a type with a multiplication function (Brent Yorgey) 4. problem running yi on OS X (Richard Talley) 5. hide Perl code inside Haskell program (Hong Yang) 6. Re: hide Perl code inside Haskell program (Jos? Prous) 7. Parsec 2 and Parsec 3 (John Velman) 8. Re: Parsec 2 and Parsec 3 (Chadda? Fouch?) 9. Re: Parsec 2 and Parsec 3 (John Velman) -- Message: 1 Date: Wed, 9 Sep 2009 17:05:04 -0400 From: Joe Fredette jfred...@gmail.com Subject: Re: [Haskell-beginners] Problems defining a type with a multiplication function To: Amy de Buitl?ir a...@nualeargais.ie Cc: beginners@haskell.org Message-ID: 27841e46-cebb-4859-a40f-c62f521c3...@gmail.com Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes You need to write an instance of the Num class, eg instance Num Quaternion where (Q a b c d) + (Q e f g h) = ... (Q a b c d) * (Q e f g h) = ... etc This allows Haskell to overload things like numbers. You seem to be headed in the right direction w/ your type signature, except (*) has type Num a = a - a - a Which means For any type `a` that is an instance of the type class `Num`, this is a closed binary function on that type HTH /Joe On Sep 9, 2009, at 4:51 PM, Amy de Buitléir wrote: I'm trying to define a Quaternion, which is sort of a four-element vector with special rules for multiplication. - Quaternion.hs - data Quaternion = Quaternion Double Double Double Double deriving (Show) (*) :: (Quaternion a) = a - a - a (*) (Quaternion w1 x1 y1 z1) (Quaternion w2 x2 y2 z2) = Quaternion w x y z where w = w1*w2 - x1*x2 - y1*y2 - z1*z2 x = x1*w2 + w1*x2 + y1*z2 - z1*y2 y = w1*y2 - x1*z2 + y1*w2 + z1*x2 z = w1*z2 + x1*y2 - y1*x2 + z1*w2 - end code - When I try to load this into ghci, I get: Quaternion.hs:6:13: Ambiguous occurrence `*' It could refer to either `Main.*', defined at Quaternion.hs:5:0 or `Prelude.*', imported from Prelude ... and lots more messages like that. I understand roughly what the message means, but I don't know how to tell it that when I use * within the definition, I just want ordinary multiplication. Thanks in advance for any help! Amy ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- Message: 2 Date: Wed, 9 Sep 2009 17:10:38 -0400 From: John Dorsey hask...@colquitt.org Subject: Re: [Haskell-beginners] Problems defining a type with a multiplication function To: beginners@haskell.org Message-ID: 20090909211038.gj14...@colquitt.org Content-Type: text/plain; charset=us-ascii Amy, instance Num Quaternion where Use this (from Joe's email), and not instance Num (Quaternion a) this (from mine). I had skimmed your code too quickly and wrote the above in error because I'd thought you had make Quaternion parametric. Unless you want the parametricity, as in: data Quaternion a = Quaternion a a a a class (Num a) = Num (Quaternion a) where ... Cheers, John -- Message: 3 Date: Wed, 9 Sep 2009 17:50:46 -0400 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] Problems defining a type with a multiplication function To: beginners@haskell.org Message-ID: 20090909215046.ga10...@seas.upenn.edu Content-Type: text/plain; charset=iso-8859-1 On Wed, Sep 09, 2009 at 09:51:34PM +0100, Amy de Buitléir wrote: - Quaternion.hs - data Quaternion = Quaternion Double Double Double Double deriving (Show) (*) :: (Quaternion a) = a - a - a Also, I should point out that the '(blah) = ...' syntax is only for type *classes*; Quaternion is just a data type so it doesn't make sense to use it in this way. The type signature instead ought to just say (*) :: Quaternion - Quaternion - Quaternion although as others have pointed out you will still get the error about (*) being ambiguous. You can either implement Num as others have suggested, or just use a
Beginners Digest, Vol 15, Issue 8
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: hide Perl code inside Haskell program (Hong Yang) 2. Re: hide Perl code inside Haskell program (Khudyakov Alexey) 3. Maybe, Either (Michael Mossey) 4. Re: Maybe, Either (Yusaku Hashimoto) 5. Re: Maybe, Either (Michael Snoyman) 6. Re: Maybe, Either (Brent Yorgey) 7. parse error on input (John Moore) 8. Re: parse error on input (Colin Paul Adams) -- Message: 1 Date: Fri, 11 Sep 2009 16:18:01 -0500 From: Hong Yang hyang...@gmail.com Subject: Re: [Haskell-beginners] hide Perl code inside Haskell program To: Jos? Prous hien...@gmail.com Cc: beginners@haskell.org Message-ID: f31db34d0909111418q36ec8889y5deae601fc08...@mail.gmail.com Content-Type: text/plain; charset=utf-8 This way works fine if the program has no arguments. What if I have to pass arguments such as -i input -o output? Thanks, Hong On Thu, Sep 10, 2009 at 12:45 PM, José Prous hien...@gmail.com wrote: you are putting the perl script as the name of the command you can do something like: rawSystem perl [-e,print \testing ...\n\; ] this is equivalent to call in the shell: perl -e print \testing ...\; (sorry Hong I din't put reply to all in the fist mail) On Thu, Sep 10, 2009 at 1:24 PM, Hong Yang hyang...@gmail.com wrote: I was trying to hide Perl code inside Haskell program like the following: module Main where import System.Environment (getArgs) import System.Cmd main = do args - getArgs rawSystem pl args where pl = #!/usr/bin/perl\n ++ print \testing ...\n\; The program can run, but generates no output at all. Can someone tell me any other tricks which might be missing? (Do we need to use pipe here?) Thanks, Hong ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090911/48f22a56/attachment-0001.html -- Message: 2 Date: Sat, 12 Sep 2009 12:19:42 +0400 From: Khudyakov Alexey alexey.sklad...@gmail.com Subject: Re: [Haskell-beginners] hide Perl code inside Haskell program To: beginners@haskell.org Message-ID: 200909121219.42576.alexey.sklad...@gmail.com Content-Type: Text/Plain; charset=utf-8 Ð ÑообÑении Ð¾Ñ Ð¡ÑббоÑа 12 ÑенÑÑбÑÑ 2009 01:18:01 авÑÐ¾Ñ Hong Yang напиÑал: This way works fine if the program has no arguments. What if I have to pass arguments such as -i input -o output? You can just run perl and feed you program to perl's stdin. With this you can add all flags you like Shell $ echo 'print fff\n; $i=1; print $i\n;' | perl fff 1 -- Message: 3 Date: Sat, 12 Sep 2009 08:14:28 -0700 From: Michael Mossey m...@alumni.caltech.edu Subject: [Haskell-beginners] Maybe, Either To: beginners@haskell.org Message-ID: 4aabbad4.4090...@alumni.caltech.edu Content-Type: text/plain; charset=ISO-8859-1; format=flowed I want to use 'lookup' inside an Either String monad. So I want to write something like eitherLookup :: Eq a = String - a - [(a,b)] - Either String b eitherLookup s x ps = case lookup x ps of Just y - Right y Nothing - Left s Is there such a function existing? Thanks, Mike -- Message: 4 Date: Sun, 13 Sep 2009 00:51:56 +0900 From: Yusaku Hashimoto nonow...@gmail.com Subject: Re: [Haskell-beginners] Maybe, Either To: Michael Mossey m...@alumni.caltech.edu Cc: beginners@haskell.org Message-ID: d17c24b90909120851h3a5e61eaw124b8832510eb...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 I think there is no such function in standard library. But you can also do the same by `maybe (Left err) Right (lookup key assoc)` without defining eitherLookup. HTH -nwn On Sun, Sep 13, 2009 at 12:14 AM, Michael Mossey m...@alumni.caltech.edu wrote: I want to use 'lookup' inside an Either String monad. So I want to write something like eitherLookup :: Eq a = String - a - [(a,b)] - Either String b eitherLookup s x ps = case lookup x ps of             Just y - Right y             Nothing - Left s Is there such a function existing? Thanks, Mike
Beginners Digest, Vol 15, Issue 9
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Maybe, Either (Michael Snoyman) 2. Re: Maybe, Either (Michael P Mossey) 3. Re: Maybe, Either (Brent Yorgey) 4. Re: Maybe, Either (Brandon S. Allbery KF8NH) 5. Re: Maybe, Either (Yusaku Hashimoto) 6. Re: Maybe, Either (Conor McBride) 7. Re: Maybe, Either (Heinrich Apfelmus) -- Message: 1 Date: Mon, 14 Sep 2009 21:42:22 +0300 From: Michael Snoyman mich...@snoyman.com Subject: Re: [Haskell-beginners] Maybe, Either To: Brent Yorgey byor...@seas.upenn.edu Cc: beginners@haskell.org Message-ID: 29bf512f0909141142m1d5129f0t6a744d691cc16...@mail.gmail.com Content-Type: text/plain; charset=utf-8 On Sun, Sep 13, 2009 at 3:40 PM, Brent Yorgey byor...@seas.upenn.eduwrote: On Sat, Sep 12, 2009 at 09:13:58PM +0300, Michael Snoyman wrote: I often times have to write a lookup function that returns its value into any monad instead of just Maybe. For example: mLookup :: (Eq k, Monad m) = k - [(k, v)] - m v mLookup k pairs = case lookup k pairs of Nothing - fail mLookup: nothing found Just v - return v This is actually the type that the lookup function USED to have, but it was changed since monads actually have nothing to do with failing (the fail method is just a hack used to handle pattern-match failures in do-notation). Probably a better implementation of this would be mLookup :: (Eq k, MonadPlus m) = k - [(k,v)] - m v mLookup k pairs = maybe mzero return (lookup k pairs) I understand that fail being in Monad is controversial, but my version of the function works in *all* monads. This is very useful for: 1) Quickly writing up code in the IO monad (ie, for a shell script) 2) Check out the data-objects library; having an mLookup function makes dealing with mappings very convenient. Michael -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090914/437f6726/attachment-0001.html -- Message: 2 Date: Mon, 14 Sep 2009 13:39:04 -0700 From: Michael P Mossey m...@alumni.caltech.edu Subject: Re: [Haskell-beginners] Maybe, Either To: Michael Snoyman mich...@snoyman.com, beginners beginners@haskell.org Message-ID: 4aaea9e8.9070...@alumni.caltech.edu Content-Type: text/plain; charset=UTF-8; format=flowed Michael Snoyman wrote: Can you give me a better idea of what you mean by catching errors? That could mean a lot of things. Michael Hi Michael, I mean that I need my software not to exit the program on an error condition, but have a higher level catch of that condition which handles it gracefully. I'm writing a musical score editor for personal use in my spare hobby time. Because it's just a bit of spare time, I can't make a promise my software won't have bugs. When I'm working on a score, I don't want to lose my work when an error occurs, such as internal errors that violate the invariants I've established in my data structures. So any action that results in an error should trigger a message box that says such-and-such error and otherwise leave the data unchanged. Then I can save my work and attempt to debug the problem. Thanks, Mike -- Message: 3 Date: Mon, 14 Sep 2009 20:08:08 -0400 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] Maybe, Either To: beginners@haskell.org Message-ID: 20090915000808.ga12...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Mon, Sep 14, 2009 at 09:42:22PM +0300, Michael Snoyman wrote: On Sun, Sep 13, 2009 at 3:40 PM, Brent Yorgey byor...@seas.upenn.eduwrote: On Sat, Sep 12, 2009 at 09:13:58PM +0300, Michael Snoyman wrote: I often times have to write a lookup function that returns its value into any monad instead of just Maybe. For example: mLookup :: (Eq k, Monad m) = k - [(k, v)] - m v mLookup k pairs = case lookup k pairs of Nothing - fail mLookup: nothing found Just v - return v This is actually the type that the lookup function USED to have, but it was changed since monads actually have nothing to do with failing (the fail method is just a hack used to handle pattern-match failures in do-notation). Probably a better implementation of this would be mLookup :: (Eq k, MonadPlus m) = k
Beginners Digest, Vol 15, Issue 10
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Maybe, Either (Michael Mossey) 2. Re: Maybe, Either (Michael Snoyman) 3. Re: Maybe, Either (Yusaku Hashimoto) 4. Re: Maybe, Either (Michael Snoyman) 5. Re: Maybe, Either (Brandon S. Allbery KF8NH) -- Message: 1 Date: Tue, 15 Sep 2009 06:45:14 -0700 (PDT) From: Michael Mossey m...@alumni.caltech.edu Subject: Re: [Haskell-beginners] Maybe, Either To: Conor McBride co...@strictlypositive.org Cc: beginners@haskell.org Message-ID: 1227.75.50.163.142.1253022314.squir...@mail.alumni.caltech.edu Content-Type: text/plain;charset=iso-8859-1 As a beginner, I'm not directly following the usefulness of these alternative implementations. I thought I would give some example code. Here I am trying to handle errors with Either String. You can read it here or in hpaste.org: http://hpaste.org/fastcgi/hpaste.fcgi/view?id=9393#a9393 import Data.Ratio import qualified Data.Map as Map -- An elemental music object such as note, rest, dynamic mark, etc. data MusicObject = MusicObject ... -- A composition has several streams. A stream could be a continuous -- melody that appears on a single staff, or other types of data that -- are arranged serially in time. data Time = Rational data StreamId = StreamId ... data MusicStream = (StreadId, Map.Map Time MusicObject) data Comp = [MusicStream] -- A cursor is a concept used to point to a note or generalized location -- in the composition so that editing can be done at that point. For now, -- all we need is to point to the stream and time. data Cursor = Cursor { getCurId :: StreamId , getCurTime :: Time } -- Utility to make it easier to annotate an Either monad with a function -- that catches an error message, prepends a context message, and rethrows. ce :: String - Either String a - Either String a ce c = (flip catchError) (\s - throwError (c ++ \n ++ s)) -- Utility to replace an item in an assoc list, inside the Either String -- monad. replaceAlist :: Eq a = a - b - [(a,b)] - Either String [(a,b)] replaceAlist _ _ [] = throwError Item not found in alist. replaceAlist iid obj (x:xs) = if fst x == iid then return $ (iid,obj) : xs else do rem - replaceAlist iid obj xs return $ x : rem ... -- Delete a note from a composition. Deleting the last note in a stream is -- an error condition. -- -- Conditions that will cause an error: -- - cursor stream id doesn't exist in the composition -- - there is no note at the given cursor -- - there is only one note in the stream (so deleting it would delete -- the last note) compDeleteNote :: Cursor - Comp - Either String Comp compDeleteNote cur comp = ce In compeDeleteNote: $ do let Cursor { getCurId=iid, getCurTime=t } = cur -- First internal error might occur if no stream with the cursor's id -- occurs in the Comp. oldMap - maybe (Left no such stream) Right (lookup iid comp) -- Second internal error: no music object is found at the cursor's time. moAtCur - maybe (Left no m.o. at cursor) Right (Map.lookup t oldMap) let durAtCur = getDur moAtCur (l,r) = Map.split t oldMap r' = Map.mapKeys (\k - k - durAtCur) r joined = Map.union l r' -- Third error condition: this action deleted the last note. if Map.null joined then (Left deleted last note) else Right () replaceAlist iid joined comp -- Message: 2 Date: Tue, 15 Sep 2009 18:56:19 +0300 From: Michael Snoyman mich...@snoyman.com Subject: Re: [Haskell-beginners] Maybe, Either To: Brandon S. Allbery KF8NH allb...@ece.cmu.edu Cc: beginners@haskell.org Message-ID: 29bf512f0909150856l2d20889cr87b881f129789...@mail.gmail.com Content-Type: text/plain; charset=utf-8 On Tue, Sep 15, 2009 at 6:21 AM, Brandon S. Allbery KF8NH allb...@ece.cmu.edu wrote: On Sep 14, 2009, at 14:42 , Michael Snoyman wrote: I understand that fail being in Monad is controversial, but my version of the function works in *all* monads. This is very Not really; fail in non-MonadPlus-es is a rather poorly defined notion, and there are no guarantees that the result will be at all sane. mzero is well defined. mzero also does not allow giving error messages. There are times when you want to be able to fail with an explanation of why. fail seems to fit the bill properly for this (fail taking a String argument and all...).
Beginners Digest, Vol 15, Issue 12
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. map question (Joost Kremers) 2. Re: map question (Daniel Fischer) 3. Re: map question (Brent Yorgey) 4. Re: map question (Joost Kremers) 5. How to import the Data.Char library in Hugs? (Benjamin L.Russell) 6. Re: How to import the Data.Char library in Hugs? (Adrian Neumann) 7. Re: How to import the Data.Char library in Hugs? (Daniel Fischer) 8. Re: map question (Tom Doris) 9. Re: map question (Magnus Therning) 10. Re: map question (Tommy M. McGuire) -- Message: 1 Date: Thu, 17 Sep 2009 13:31:38 +0200 From: Joost Kremers joostkrem...@fastmail.fm Subject: [Haskell-beginners] map question To: beginners@haskell.org Message-ID: 20090917113138.gc15...@enterprise.localdomain Content-Type: text/plain; charset=utf-8 Hi all, I've just started learning Haskell and while experimenting with map a bit, I ran into something I don't understand. The following commands do what I'd expect: Prelude map (+ 1) [1,2,3,4] [2,3,4,5] Prelude map (* 2) [1,2,3,4] [2,4,6,8] Prelude map (/ 2) [1,2,3,4] [0.5,1.0,1.5,2.0] Prelude map (2 /) [1,2,3,4] [2.0,1.0,0.,0.5] But I can't seem to find a way to get map to substract 1 from all members of the list. The following form is the only one that works, but it doesn't give the result I'd expect: Prelude map ((-) 1) [1,2,3,4] [0,-1,-2,-3] I know I can use an anonymous function, but I'm just trying to understand the result here... I'd appreciate any hints to help me graps this. TIA Joost -- Joost Kremers, PhD University of Frankfurt Institute for Cognitive Linguistics Grüneburgplatz 1 60629 Frankfurt am Main, Germany -- Message: 2 Date: Thu, 17 Sep 2009 13:50:27 +0200 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] map question To: beginners@haskell.org Message-ID: 200909171350.27848.daniel.is.fisc...@web.de Content-Type: text/plain; charset=utf-8 Am Donnerstag 17 September 2009 13:31:38 schrieb Joost Kremers: Hi all, I've just started learning Haskell and while experimenting with map a bit, I ran into something I don't understand. The following commands do what I'd expect: Prelude map (+ 1) [1,2,3,4] [2,3,4,5] Prelude map (* 2) [1,2,3,4] [2,4,6,8] Prelude map (/ 2) [1,2,3,4] [0.5,1.0,1.5,2.0] Prelude map (2 /) [1,2,3,4] [2.0,1.0,0.,0.5] But I can't seem to find a way to get map to substract 1 from all members of the list. The following form is the only one that works, but it doesn't give the result I'd expect: Prelude map ((-) 1) [1,2,3,4] [0,-1,-2,-3] I know I can use an anonymous function, but I'm just trying to understand the result here... I'd appreciate any hints to help me graps this. (-) a b = a - b, so (((-) 1) x) = 1 - x and you've mapped (\x - 1-x) over the list. You want to map (\x - x-1), which is map (subtract 1) list or map (flip (-) 1) list (or map (+ (-1)) list) TIA Joost -- Message: 3 Date: Thu, 17 Sep 2009 08:01:50 -0400 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] map question To: beginners@haskell.org Message-ID: 20090917120150.ga20...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Thu, Sep 17, 2009 at 01:31:38PM +0200, Joost Kremers wrote: But I can't seem to find a way to get map to substract 1 from all members of the list. The following form is the only one that works, but it doesn't give the result I'd expect: Prelude map ((-) 1) [1,2,3,4] [0,-1,-2,-3] By the way, the reason map (+1) [1,2,3,4] works but map (-1) [1,2,3,4] doesn't is because of an ugly corner of Haskell syntax: -1 here is parsed as negative one, rather than an operator section with subtraction. The 'subtract' function is provided exactly for this purpose, so that you can write map (subtract 1) [1,2,3,4] instead. -Brent -- Message: 4 Date: Thu, 17 Sep 2009 14:01:47 +0200 From: Joost Kremers joostkrem...@fastmail.fm Subject: Re: [Haskell-beginners] map question To: beginners@haskell.org Message-ID: 20090917120147.ga29...@enterprise.localdomain Content-Type: text/plain; charset=utf-8 On Thu, Sep 17, 2009 at 01:50:27PM +0200, Daniel Fischer wrote: Prelude map ((-) 1) [1,2,3,4] [0,-1,-2,-3] I know I can use an anonymous function, but I'm just trying to understand the result here... I'd appreciate any hints to help me graps
Beginners Digest, Vol 15, Issue 13
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: How to import the Data.Char library in Hugs? (Benjamin L.Russell) 2. Re: How to import the Data.Char library in Hugs? (Benjamin L.Russell) 3. Re: Re: How to import the Data.Char library in Hugs? (Daniel Fischer) 4. Re: How to import the Data.Char library in Hugs? (Benjamin L.Russell) 5. Re: How to import the Data.Char library in Hugs? (Benjamin L.Russell) 6. Re: Maybe, Either (Heinrich Apfelmus) 7. Re: Re: How to import the Data.Char library in Hugs? (Daniel Fischer) 8. type class question (Ben) -- Message: 1 Date: Fri, 18 Sep 2009 11:27:31 +0900 From: Benjamin L.Russell dekudekup...@yahoo.com Subject: [Haskell-beginners] Re: How to import the Data.Char library in Hugs? To: beginners@haskell.org Message-ID: 0sr5b5524g1078cv68dt1vm1vsaagsr...@4ax.com Content-Type: text/plain; charset=us-ascii On Thu, 17 Sep 2009 15:04:07 +0200, Daniel Fischer daniel.is.fisc...@web.de wrote: Am Donnerstag 17 September 2009 14:41:47 schrieb Benjamin L.Russell: My apologies if this is an extremely elementary question, but I am having difficulties in importing the Data.Char library in Hugs. Hugs :a Data.Char Data.Char Thank you; that was exactly the information for which I was looking. Incidentally, what option name does 'a' represent? That one doesn't appear when I type :?. Shouldn't it appear in that list? -- Benjamin L. Russell -- Benjamin L. Russell / DekuDekuplex at Yahoo dot com http://dekudekuplex.wordpress.com/ Translator/Interpreter / Mobile: +011 81 80-3603-6725 Furuike ya, kawazu tobikomu mizu no oto. -- Matsuo Basho^ -- Message: 2 Date: Fri, 18 Sep 2009 11:39:50 +0900 From: Benjamin L.Russell dekudekup...@yahoo.com Subject: [Haskell-beginners] Re: How to import the Data.Char library in Hugs? To: beginners@haskell.org Message-ID: 8ks5b5t6snt7de6sf1irclis3oftjub...@4ax.com Content-Type: text/plain; charset=us-ascii On Thu, 17 Sep 2009 15:02:21 +0200, Adrian Neumann aneum...@inf.fu-berlin.de wrote: You do :l Data.Char That command didn't work; see the following results: --8---cut here---start-8--- Hugs:| Data.Char Command not recognised. Type :? for help Hugs --8---cut here---end---8--- -- Benjamin L. Russell As far as I know you can't have multiple loaded modules unless you put them in a file and load that. Regards, Adrian Benjamin L.Russell schrieb: My apologies if this is an extremely elementary question, but I am having difficulties in importing the Data.Char library in Hugs. In GHCi, the command import Data.Char works correctly, as follows: --8---cut here---start-8--- GHCi, version 6.10.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \/\/ /_/\/|_| Type :? for help. Prelude import Data.Char Prelude Data.Char --8---cut here---end---8--- However, in Hugs, the same command fails with an error, as follows: --8---cut here---start-8--- __ __ __ __ ___ _ || || || || || || ||__ Hugs 98: Based on the Haskell 98 standard ||___|| ||__|| ||__|| __|| Copyright (c) 1994-2005 ||---|| ___|| World Wide Web: http://haskell.org/hugs || || Bugs: http://hackage.haskell.org/trac/hugs || || Version: 20051031 _ Haskell 98 mode: Restart with command line option -98 to enable extensions Type :? for help Hugs import Data.Char ERROR - Syntax error in expression (unexpected keyword import) Hugs --8---cut here---end---8--- Does anybody know how to import the Data.Char library in Hugs? -- Benjamin L. Russell -- Benjamin L. Russell / DekuDekuplex at Yahoo dot com http://dekudekuplex.wordpress.com/ Translator/Interpreter / Mobile: +011 81 80-3603-6725 Furuike ya, kawazu tobikomu mizu no oto. -- Matsuo Basho^
Beginners Digest, Vol 15, Issue 15
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Vaccum Cairo Errors (Daniel Fischer) 2. Question regarding infering the type of afunction (MoC) 3. Re: Question regarding infering the type of afunction (Joe Fredette) 4. Re: Question regarding infering the type of afunction (Daniel Fischer) 5. Re: Question regarding infering the type of afunction (MoC) 6. edit-compile-test loop (Tom Doris) 7. Re: edit-compile-test loop (Joe Fredette) 8. Re: edit-compile-test loop (Tom Doris) -- Message: 1 Date: Mon, 21 Sep 2009 16:37:04 +0200 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] Vaccum Cairo Errors To: beginners@haskell.org Message-ID: 200909211637.04184.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-15 Am Montag 21 September 2009 16:21:10 schrieb aditya siram: Hi all, I am trying out the awesome Vacuum Cairo package on GHC 6.10.3 but I am getting some interesting errors. The following works in GHCI: view [1 .. 3] But the following does not work in GHCI: let x = [1 .. 3] view x or, x - return [1 .. 3] view x For the last two I get: context: (:)|0 - {1|1, (:)|2} ghc: ../../src/xcb_lock.c:77: _XGetXCBBuffer: Assertion `((int) ((xcb_req) - (dpy-request)) = 0)' failed. Aborted and GHCI quits. Any ideas? thanks ... deech Probably it's that in the last two, x is given the type [Integer] by ghci (see http://www.haskell.org/haskellwiki/Monomorphism_Restriction ) while view expects an [Int]. Do let x = [1 .. 3] :: [Int] view x and x - return ([1 .. 3] :: [Int]) view x work? -- Message: 2 Date: Mon, 21 Sep 2009 21:47:40 +0200 From: MoC m...@coders-haven.net Subject: [Haskell-beginners] Question regarding infering the type of a function To: Haskell Beginners beginners@haskell.org Message-ID: 4ab7d85c.5050...@coders-haven.net Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi everybody, today somebody on IRC (#haskell on Freenode) jokingly submitted the following to lambdabot: (.) (.) It turned out that (.) (.) :: (a1 - b - c) - a1 - (a - b) - a - c. I got interested in why that is so, but unfortunately I have not been able to figure this out by myself yet. I know that partial application is used, but don't know to what it would expand to and why. Could someone please explain? (I asked on the channel, but nobody did answer so I thought I'd try my luck here.) Regards, MoC -- Message: 3 Date: Mon, 21 Sep 2009 16:18:45 -0400 From: Joe Fredette jfred...@gmail.com Subject: Re: [Haskell-beginners] Question regarding infering the type of afunction To: MoC m...@coders-haven.net Cc: Haskell Beginners beginners@haskell.org Message-ID: f6e04b47-bb90-4c06-806b-ce35c482b...@gmail.com Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes The type of `(.)` is (.) :: (b-c) - (a-b) - a - c it can be defined as: (.) f g x = f (g x) So, let f = (.), then we can plug that in and make it infix in the defn to get: (.) (.) g x q y = g x . q $ y I had to add a few variables there to make it pointed, as opposed to the more succint semipointfree version: (.) (.) g x = (.) g x So we can see that this function, `(.) (.)` takes four arguments, a function on 2 inputs (g, because (.) is going to feed it another one, and it's taking one already, in the form of x). One of the variables of appropriate some arbitrary type `t` (since g is the only thing that will ever see it, you can think of it as a kind of index to an indexed family of functions of type `b-c`.) giving `(.) (.)` just `x` will reduce the type to something you should recognize, that is if: foo x = something in (\ g q y - (.) (.) g x' q y) then foo has type: foo :: (b - c) - (a - b) - a - c eg, foo = (.) So, (.) (.) effectively says, Given a indexed family of functions from `b - c`, indexed by some type `t` compose the `t`th function with some function `q` from `a - b`, and return a function of type `a - c`. You might use it for something like mapping over a list at a given starting point, or something. HTH. /Joe On Sep 21, 2009, at 3:47 PM, MoC wrote: Hi everybody, today somebody on IRC (#haskell on Freenode) jokingly submitted the following to lambdabot: (.) (.) It turned out that (.) (.) :: (a1 - b - c) - a1
Beginners Digest, Vol 15, Issue 20
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Distributing executables (Magnus Therning) 2. Re: Distributing executables (Magnus Therning) 3. Re: Distributing executables (Lyndon Maydwell) 4. Can you identify this recursion pattern please? (Colin Paul Adams) 5. Re: Can you identify this recursion pattern please? (Colin Paul Adams) 6. remove XML tags using Text.Regex.Posix (Robert Ziemba) 7. Re: remove XML tags using Text.Regex.Posix (Colin Paul Adams) 8. Re: remove XML tags using Text.Regex.Posix (Patrick LeBoutillier) 9. Re: remove XML tags using Text.Regex.Posix (Magnus Therning) -- Message: 1 Date: Tue, 29 Sep 2009 10:30:44 +0100 From: Magnus Therning mag...@therning.org Subject: Re: [Haskell-beginners] Distributing executables To: Lyndon Maydwell maydw...@gmail.com Cc: beginners@haskell.org Message-ID: e040b520909290230w76977dedj3de0c8b3781a6...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Tue, Sep 29, 2009 at 10:19 AM, Lyndon Maydwell maydw...@gmail.com wrote: No love for OS X? No, not from me personally ;-) Seriously, I simply don't know anything about OSX. I've never owned a McComputer. Though I suspect OSX isn't quite as broken as Windows in relation to installers. /M -- Magnus Therning(OpenPGP: 0xAB4DFBA4) magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org http://therning.org/magnus identi.ca|twitter: magthe -- Message: 2 Date: Tue, 29 Sep 2009 10:32:52 +0100 From: Magnus Therning mag...@therning.org Subject: Re: [Haskell-beginners] Distributing executables To: Alp Mestan a...@mestan.fr Cc: beginners@haskell.org Message-ID: e040b520909290232u2d841050qe0a712518eece...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Tue, Sep 29, 2009 at 10:29 AM, Alp Mestan a...@mestan.fr wrote: On Tue, Sep 29, 2009 at 11:19 AM, Lyndon Maydwell maydw...@gmail.com wrote: No love for OS X? No knowledge of OS X binary/library interactions, actually :-) Magnus : I agree about Linux. At least, a cabal package is enough, since there are a lot of cabal-to-insert distro package format here tools around. For Windows, which tool do you know that'd make it for Haskell apps ? I don't know of any Haskell-specific ones, but I'd be surprised if you can't make NSIS or WiX create an installer for a Haskell binary. /M -- Magnus Therning(OpenPGP: 0xAB4DFBA4) magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org http://therning.org/magnus identi.ca|twitter: magthe -- Message: 3 Date: Tue, 29 Sep 2009 17:35:28 +0800 From: Lyndon Maydwell maydw...@gmail.com Subject: Re: [Haskell-beginners] Distributing executables To: Magnus Therning mag...@therning.org Cc: beginners@haskell.org Message-ID: da8fea9e0909290235g3c726338v1a250a4f2ade9...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 I was thinking more along the lines of how reasonable it would be to ask a non-technical user to build a program you wish to distribute from source. On linux / bsd /etc it would probably be unsurprising, but it may be asking too much of windows and mac users. On Tue, Sep 29, 2009 at 5:30 PM, Magnus Therning mag...@therning.org wrote: On Tue, Sep 29, 2009 at 10:19 AM, Lyndon Maydwell maydw...@gmail.com wrote: No love for OS X? No, not from me personally ;-) Seriously, I simply don't know anything about OSX.  I've never owned a McComputer.  Though I suspect OSX isn't quite as broken as Windows in relation to installers. /M -- Magnus Therning             (OpenPGP: 0xAB4DFBA4) magnusï¼ therningï¼org      Jabber: magnusï¼ therningï¼org http://therning.org/magnus     identi.ca|twitter: magthe -- Message: 4 Date: Tue, 29 Sep 2009 18:02:40 +0100 From: Colin Paul Adams co...@colina.demon.co.uk Subject: [Haskell-beginners] Can you identify this recursion pattern please? To: beginners@haskell.org Message-ID: m34oql7kgf@colina.demon.co.uk Content-Type: text/plain; charset=us-ascii This looks like some kind of unfold to me. Can you help? I have the following code that works for the first two levels: -- get the list of all (recursive) child gallery names -- first, just the immediate children childNames - childGalleries db (name gallery) -- now let's try the
Beginners Digest, Vol 16, Issue 7
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Problem to compile an example of DataParallel Haskell (Brent Yorgey) 2. Re: using quickcheck for blackbox testing for3rd party apps. (Brent Yorgey) 3. Re: using quickcheck for blackbox testing for 3rdparty apps. (Daniel Fischer) 4. new locale? (Robert Wills) 5. sleep in Haskell (Michael Mossey) 6. Re: sleep in Haskell (Joe Fredette) 7. Re: sleep in Haskell (Michael Mossey) 8. Re: sleep in Haskell (Michael Mossey) 9. Re: sleep in Haskell (Joe Fredette) 10. Re: sleep in Haskell (Joe Fredette) -- Message: 1 Date: Tue, 13 Oct 2009 11:51:39 -0400 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] Problem to compile an example of Data Parallel Haskell To: beginners@haskell.org Message-ID: 20091013155139.ga2...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Mon, Oct 12, 2009 at 02:26:28PM +0200, Edgar GOMES DE ARAUJO wrote: Hi, I have tried to compile an example of DPH (Data prallel Haskell) but I am not getting any success. The target is the concmop.hs (http://darcs.haskell.org/ghc-6.10/packages/dph/examples/concomp/) for calculate connected components in a graph. I am using GHC 6.10.4 compiled with extras libs (which also includes DPH 0.3.0). I've got this error. Seems that GHC can't find these functions/types. - ed...@edgar-ubuntu:~/Desktop/dph$ ghc --make -fdph-par -XTypeOperators ./concomp.hs [1 of 4] Compiling Graph( Graph.hs, Graph.o ) Graph.hs:11:45: Not in scope: type constructor or class `:*:' Graph.hs:23:6: Not in scope: `hPutU' Graph.hs:33:15: Not in scope: `hGetU' - Perhaps that file is just missing an import? IIRC these things are from Data.Array.Vector, from the uvector package. -Brent -- Message: 2 Date: Tue, 13 Oct 2009 12:04:52 -0400 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] using quickcheck for blackbox testing for 3rd party apps. To: beginners@haskell.org Message-ID: 20091013160452.gb2...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Mon, Oct 12, 2009 at 11:51:49AM +0530, Srikanth K wrote: However, being a newbie, I am not able to understand how I can extract the Response part from the IO Response. I want something as follows prop_App state_x command_y = (abstract_App state_x command_y ) == (real_App state_x command_y) The issue here is that since the reall_App would return a IO Response and not Response I cannot really compare the abstract_App with the real_App. Any thought on how I can extract the value from the IO Response so that I can compare the the two implementations for equvivalence. Hi Srikanth, The short answer is: you can't extract a Response from an IO Response. Once something is infected with IO, there's no cure!* However, you can compare the responses if you make the result of prop_App an IO action itself: prop_App :: State - Command - IO Bool prop_App state_x command_y = do realResponse - real_App state_x command_y return $ abstract_App state_x command_y == realResponse Off the top of my head I'm not sure of the proper way to run such monadic tests with QuickCheck, but it can definitely be done. -Brent * Some smart-alecks might pipe up with something about unsafePerformIO here. But that's not a cure, it's more like performing an emergency tracheotomy with a ballpoint pen. -- Message: 3 Date: Tue, 13 Oct 2009 19:34:36 +0200 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] using quickcheck for blackbox testing for 3rd party apps. To: beginners@haskell.org, haskell-c...@haskell.org Message-ID: 200910131934.36808.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-1 Am Dienstag 13 Oktober 2009 18:04:52 schrieb Brent Yorgey: Brent * Some smart-alecks might pipe up with something about unsafePerformIO here. But that's not a cure, it's more like performing an emergency tracheotomy with a ballpoint pen. Quote of the month! -- Message: 4 Date: Wed, 14 Oct 2009 05:44:34
Beginners Digest, Vol 16, Issue 10
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: parsing upto n items with parsec (Christian Maeder) 2. Re: is there a best os to easily install externallibraries ? (david hodgetts) 3. Re: map question (Will Ness) 4. Re: Re: map question (Deniz Dogan) 5. Re: Re: map question (Brent Yorgey) 6. Re: new locale? (Brent Yorgey) 7. Re: map question (Will Ness) 8. I/O (John Moore) 9. Re: I/O (Daniel Fischer) 10. Re: Re: map question (Daniel Fischer) -- Message: 1 Date: Sat, 17 Oct 2009 11:15:40 +0200 From: Christian Maeder christian.mae...@dfki.de Subject: [Haskell-beginners] Re: parsing upto n items with parsec To: Ashish Agarwal agarwal1...@gmail.com Cc: beginners@haskell.org Message-ID: 4ad98b3c.7080...@dfki.de Content-Type: text/plain; charset=ISO-8859-1 Ashish Agarwal schrieb: Hi. I'm just learning Parsec and Haskell. It is a great library, and I see how many lets you parse 0 or more items, many1 parses 1 or more items, and count parses exactly n items. However, there is no combinator that parses between m and n items. What would be the best implementation for this? I would write an upTo parser with the same type as count that parses not exactly but at most n items. Your desired parser is than the concatenated results of count m p and upTo (n - m) p (achieved by liftM2 (++)). For upTo a recursive definition seems best (other may come up with tricky combinator application.) upTo 0 p (or something less than 0) returns [] and upTo n p is an option [] ... parser of one p result followed by the upTo (n - 1) p result: option [] (liftM2 (:) p (upTo (n - 1) p)) HTH Christian Another possibility is to use many and check if the resulting list has the desired length (if not fail), but that may consume too many tokens that subsequent parsers are supposed to consume. -- Message: 2 Date: Sat, 17 Oct 2009 12:00:23 +0200 From: david hodgetts david.demainlal...@gmail.com Subject: Re: [Haskell-beginners] is there a best os to easily install externallibraries ? To: beginners@haskell.org Message-ID: 42a5d61a0910170300nffb73co2ff69725c9f00...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 Thank you very much for the long and very informative answer. I was going to try Ubuntu, but since I have a spare machine, I think I will rather plunge deep and try to get arch linux running. Also, thanks for mentioning andLinux, I will certainly check it out. best regards david hodgetts -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20091017/4bf4d21f/attachment-0001.html -- Message: 3 Date: Sat, 17 Oct 2009 18:29:39 + (UTC) From: Will Ness will_...@yahoo.com Subject: [Haskell-beginners] Re: map question To: beginners@haskell.org Message-ID: loom.20091017t202435-...@post.gmane.org Content-Type: text/plain; charset=us-ascii Brent Yorgey byorgey at seas.upenn.edu writes: By the way, the reason map (+1) [1,2,3,4] works but map (-1) [1,2,3,4] doesn't is because of an ugly corner of Haskell syntax: -1 here is parsed as negative one, rather than an operator section with subtraction. The 'subtract' function is provided exactly for this purpose, so that you can write map (subtract 1) [1,2,3,4] Then why wouldn't (`-`1) parse at at all? And not even (`(-)`1) ? I know this doesn't parse, my question is, why wouldn't it be made valid syntax? It seems consistent. (`mod`2) parses, why not (`-`2) ? -- Message: 4 Date: Sat, 17 Oct 2009 20:41:30 +0200 From: Deniz Dogan deniz.a.m.do...@gmail.com Subject: Re: [Haskell-beginners] Re: map question To: Will Ness will_...@yahoo.com Cc: beginners@haskell.org Message-ID: 7b501d5c0910171141y56be9da3wa70658d090097...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 2009/10/17 Will Ness will_...@yahoo.com: Brent Yorgey byorgey at seas.upenn.edu writes: By the way, the reason map (+1) [1,2,3,4] works but map (-1) [1,2,3,4] doesn't is because of an ugly corner of Haskell syntax: -1 here is parsed as negative one, rather than an operator section with subtraction. The 'subtract' function is provided exactly for this purpose, so that you can write map (subtract 1) [1,2,3,4] Then why wouldn't (`-`1) parse at at all? And not even (`(-)`1)
Beginners Digest, Vol 16, Issue 14
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Re: \x - x 0.5 x -0.5 (aditya siram) 2. Re: Re: parsing upto n items with parsec (Chadda? Fouch?) 3. Re: Re: \x - x 0.5 x -0.5 (Brent Yorgey) 4. Re: Re: parsing upto n items with parsec (Ashish Agarwal) 5. Re: Re: \x - x 0.5 x -0.5 (Michael Mossey) -- Message: 1 Date: Mon, 19 Oct 2009 11:47:32 -0500 From: aditya siram aditya.si...@gmail.com Subject: Re: [Haskell-beginners] Re: \x - x 0.5 x -0.5 To: Jordan Cooper nefi...@gmail.com Cc: beginners@haskell.org Message-ID: 594f78210910190947l54e8ac10g53920b932a539...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 There was a mistake in the trace, please ignore the previous one and look at this. Again your viewing window should be this wide: - (liftM2 () ( 0.5) ( -0.5)) = do {x1 - ( 0.5); x2 - ( -0.5); return (() x1 x2)} = ( 0.5) = \x1 ( -0.5) = \x2 return (() x1 x2) = \r -(\x1 - ( -0.5) = \x2 return (() x1 x2)) (( 0.5) r) r = \r - (( -0.5) = \x2 return (() (( 0.5) r) x2)) r = \r - (\r' - (\x2 - return (() (const ( 0.5) r) x2)) (( -0.5) r') r') r = \r - (\r' - (return (() (( 0.5) r) (( -0.5) r'))) r') r = \r - (\r' - (const (() (( 0.5) r) (( -0.5) r'))) r') r = \r - (\r' - (() (( 0.5) r) (( -0.5) r'))) r = \r - (\r' - ((r 0.5) (r' -0.5))) r On Mon, Oct 19, 2009 at 11:42 AM, aditya siram aditya.si...@gmail.comwrote: This one had me puzzled too - so did a traced through the program below. Please make sure your viewing window is at least this wide: It was more helpful to think of this as using the ((-) r) instance of Monad. It is defined in ./libraries/base/Control/Monad/Instances.hs in your GHC source as: instance Monad ((-) r) where return = const f = k = \ r - k (f r) r And const just returns its first argument like: const 1 3 = 1 const hello world = hello And liftM2 is defined in ./libraries/base/Control/Monad.hs as : liftM2 :: (Monad m) = (a1 - a2 - r) - m a1 - m a2 - m r liftM2 f m1 m2 = do { x1 - m1; x2 - m2; return (f x1 x2) } So a trace of the program goes like this: (liftM2 () ( 0.5) ( -0.5)) = do {x1 - ( 0.5); x2 - ( -0.5); return (() x1 x2)} = ( 0.5) = \x1 ( -0.5) = \x2 return (() x1 x2) = \r -(\x1 - ( -0.5) = \x2 return (() x1 x2)) (( 0.5) r) r = \r - (return ( -0.5) = \x2 return (() (( 0.5) r) x2)) r = \r - (\r' - (\x2 - return (() (const ( 0.5) r) x2)) (( -0.5) r') r') r = \r - (\r' - (return (() (( 0.5) r) (( -0.5) r'))) r') r = \r - (\r' - (const (() (( 0.5) r) (( -0.5) r'))) r') r = \r - (\r' - (() (( 0.5) r) (( -0.5) r'))) r = \r - (\r' - ((r 0.5) (r' -0.5))) r hope this helps, -deech On Mon, Oct 19, 2009 at 10:24 AM, Jordan Cooper nefi...@gmail.com wrote: Whoa... how on earth does this work? How does it interpret the sections as Reader monads? That's a job for the reader monad. Lambda Fu, form 53 - silent reader of truth import Control.Monad import Control.Monad.Reader filter (liftM2 () ( 0.5) ( -0.5)) xs Regards, apfelmus ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20091019/cd9fb9ca/attachment-0001.html -- Message: 2 Date: Mon, 19 Oct 2009 18:55:15 +0200 From: Chadda? Fouch? chaddai.fou...@gmail.com Subject: Re: [Haskell-beginners] Re: parsing upto n items with parsec To: Ashish Agarwal agarwal1...@gmail.com Cc: Christian Maeder christian.mae...@dfki.de, beginners@haskell.org Message-ID: e9350eaf0910190955n45cb1e50s664bd7c93d5e4...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Mon, Oct 19, 2009 at 6:22 PM, Ashish Agarwal agarwal1...@gmail.com wrote: The semantics of (upTo n p) should be to parse at most n tokens, but if less than n tokens are available that should still be a successful parse. And the
Beginners Digest, Vol 16, Issue 15
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Re: \x - x 0.5 x -0.5 (Brent Yorgey) 2. Re: new locale? (Robert Wills) 3. Re: \x - x 0.5 x -0.5 (Carl Cravens) 4. Re: \x - x 0.5 x -0.5 (Michael Mossey) 5. Re: \x - x 0.5 x -0.5 (Isaac Dupree) 6. Re: \x - x 0.5 x -0.5 (Daniel Fischer) 7. Stack overflow, but hard to understand (Michael Mossey) 8. Is step by step the most natural style of thought? (Michael Mossey) 9. Re: \x - x 0.5 x -0.5 (Bas van Dijk) -- Message: 1 Date: Mon, 19 Oct 2009 16:18:32 -0400 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] Re: \x - x 0.5 x -0.5 To: beginners@haskell.org Message-ID: 20091019201832.ga5...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Mon, Oct 19, 2009 at 12:09:02PM -0700, Michael Mossey wrote: Note also there's no need for runReader or evalReader (at least not that I'm aware of) because unlike other monads, the reader monad is itself a function that takes the state to be read. Note that little-r 'reader' is just an informal name for the ((-) e) monad, which is what your code was using. Control.Monad.Reader also provides the big-R 'Reader' type, which is just a newtype wrapper around a little-r reader, and does indeed have a 'runReader' method (which just removes the newtype constructor). That is, newtype Reader r a = Reader { runReader :: r - a } C.M.Reader also provides ReaderT, a monad transformer version of Reader. -Brent -- Message: 2 Date: Mon, 19 Oct 2009 23:17:05 +0100 From: Robert Wills wrwi...@gmail.com Subject: Re: [Haskell-beginners] new locale? To: Brent Yorgey byor...@seas.upenn.edu Cc: beginners@haskell.org Message-ID: 4adce561.1050...@gmail.com Content-Type: text/plain; charset=UTF-8; format=flowed Hi, Sorry for not replying earlier. I didn't see this until Friday and didn't get much time on my computer this weekend. I asked this question because I was hoping to find System.Locale.defaultTimeLocale doesn't seem to be returning a time locale that matches what's on my system. It returns dateFmt = %m/%d/%y while my machine is set to EN_GB and so presumably it should return %d/%m/%y. In Python on my machine I get: import locale locale.getdefaultlocale() ('en_GB', 'UTF8') So anyway, I was wondering whether there was a new locale library that fixed this problem. -Rob Brent Yorgey wrote: On Wed, Oct 14, 2009 at 05:44:34AM +0100, Robert Wills wrote: Hello, http://hackage.haskell.org/package/old-locale-1.0.0.1 says This package provides the old locale library. For new code, the new locale library is recommended. Does anyone know where I would find the new library? What locale functions are you trying to use? As far as I can tell, there actually is no new locale library and functions for working with the locale have been spread across various other libraries as appropriate. -Brent ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- Message: 3 Date: Mon, 19 Oct 2009 21:19:41 -0500 From: Carl Cravens ra...@phoenyx.net Subject: Re: [Haskell-beginners] \x - x 0.5 x -0.5 To: beginners@haskell.org Message-ID: 4add1e3d.5090...@phoenyx.net Content-Type: text/plain; charset=ISO-8859-1; format=flowed Michael Mossey wrote: Is there a nifty way to write filter (\x - x 0.5 x -0.5) xs without explicitly using x? I'm pretty new to Haskell... are you looking for a *better* way to write this, or is this an exercise in exploring alternatives for the sake of understanding? I'm not seeing any of the proposed alternatives as being as clear as the lambda function, and I'd be surprised (in my ignorance) if any of them were more efficient. -- Carl D Cravens (ra...@phoenyx.net) Bad Command! Bad, Bad Command! Sit! Stay... -- Message: 4 Date: Mon, 19 Oct 2009 19:48:50 -0700 From: Michael Mossey m...@alumni.caltech.edu Subject: Re: [Haskell-beginners] \x - x 0.5 x -0.5 To: beginners@haskell.org Message-ID: 4add2512.8090...@alumni.caltech.edu Content-Type: text/plain; charset=ISO-8859-1; format=flowed Carl Cravens wrote: Michael Mossey wrote: Is there a nifty way to write filter (\x - x 0.5 x -0.5) xs without explicitly using x? I'm pretty new to Haskell... are
Beginners Digest, Vol 16, Issue 16
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: \x - x 0.5 x -0.5 (Heinrich Apfelmus) 2. Re: \x - x 0.5 x -0.5 (Stephen Tetley) 3. Re: Re: \x - x 0.5 x -0.5 (Brent Yorgey) 4. Re: \x - x 0.5 x -0.5 (Christian Maeder) 5. haskell on snow leopard (Bernardas Jankauskas) 6. Re: Re: \x - x 0.5 x -0.5 (Edward Z. Yang) 7. Re: haskell on snow leopard (Luca Ciciriello) 8. Re: haskell on snow leopard (Tom Tobin) 9. Re: SOLVED - Stack overflow, but hard to understand (Michael Mossey) 10. Re: SOLVED - Stack overflow, but hard to understand (Magnus Therning) 11. Re: SOLVED - Stack overflow, but hard to understand (Michael Mossey) -- Message: 1 Date: Tue, 20 Oct 2009 12:08:19 +0200 From: Heinrich Apfelmus apfel...@quantentunnel.de Subject: [Haskell-beginners] Re: \x - x 0.5 x -0.5 To: beginners@haskell.org Message-ID: hbk26k$bf...@ger.gmane.org Content-Type: text/plain; charset=ISO-8859-1 Brent Yorgey wrote: Note that little-r 'reader' is just an informal name for the ((-) e) monad, which is what your code was using. Control.Monad.Reader also provides the big-R 'Reader' type, which is just a newtype wrapper around a little-r reader, and does indeed have a 'runReader' method (which just removes the newtype constructor). That is, newtype Reader r a = Reader { runReader :: r - a } C.M.Reader also provides ReaderT, a monad transformer version of Reader. I thought Control.Monad.Reader also provides the needed instance Monad ((-) r) but this is actually provided by Control.Monad.Instances . Regards, apfelmus -- http://apfelmus.nfshost.com -- Message: 2 Date: Tue, 20 Oct 2009 16:29:43 +0100 From: Stephen Tetley stephen.tet...@gmail.com Subject: [Haskell-beginners] Re: \x - x 0.5 x -0.5 To: beginners@haskell.org, christian.mae...@dfki.de Message-ID: 5fdc56d70910200829h1d4b2094y93f6c8fc19c20...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 Christian Maeder wrote: Hoogle did not find a function of type: (b - b - b) - (a - b) - (a - b) - a - b or (b - c - d) - (a - b) - (a - c) - a - d But maybe such a function is worth being added to Data.Function. Hello Christian This is the big Phi or S' combinator. I would certainly second its addition to Data.Function. sprime p q r s = p (q s) (r s) Best wishes Stephen -- Message: 3 Date: Tue, 20 Oct 2009 11:37:15 -0400 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] Re: \x - x 0.5 x -0.5 To: beginners@haskell.org Message-ID: 20091020153715.ga2...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Tue, Oct 20, 2009 at 04:29:43PM +0100, Stephen Tetley wrote: Christian Maeder wrote: Hoogle did not find a function of type: (b - b - b) - (a - b) - (a - b) - a - b or (b - c - d) - (a - b) - (a - c) - a - d But maybe such a function is worth being added to Data.Function. Hello Christian This is the big Phi or S' combinator. I would certainly second its addition to Data.Function. sprime p q r s = p (q s) (r s) But this function already exists in the standard libraries: it is called liftM2/liftA2, specialized to the ((-) e) monad/applicative instance. This is what the rest of the thread has been talking about. -Brent -- Message: 4 Date: Tue, 20 Oct 2009 18:34:23 +0200 From: Christian Maeder christian.mae...@dfki.de Subject: [Haskell-beginners] Re: \x - x 0.5 x -0.5 To: Stephen Tetley stephen.tet...@gmail.com Cc: beginners@haskell.org Message-ID: 4adde68f.9080...@dfki.de Content-Type: text/plain; charset=ISO-8859-1 Stephen Tetley schrieb: Christian Maeder wrote: Hoogle did not find a function of type: (b - b - b) - (a - b) - (a - b) - a - b or (b - c - d) - (a - b) - (a - c) - a - d But maybe such a function is worth being added to Data.Function. I did not find liftM2 (or liftA2) although I knew liftM2 and instance Functor/Monad ((-) a). Hello Christian This is the big Phi or S' combinator. I would certainly second its addition to Data.Function. sprime p q r s = p (q s) (r s) At least for documentation purposes (other than this thread) such an explicit definition makes sense to be put into a source. Be it just to show the (non-)obvious. Cheers Christian Btw. for the actual problem I suggest now: (( 0.5) . abs)
Beginners Digest, Vol 16, Issue 17
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: SOLVED - Stack overflow, but hard to understand (Magnus Therning) 2. Re: SOLVED - Stack overflow, but hard to understand (Michael Mossey) 3. Haskell Output Help (Chandni Navani) 4. Re: Haskell Output Help (aditya siram) 5. Re: Haskell Output Help (aditya siram) 6. how to set command args in ghci (Kui Ma) 7. Re: how to set command args in ghci (Yusaku Hashimoto) 8. Re: how to set command args in ghci (Yusaku Hashimoto) -- Message: 1 Date: Wed, 21 Oct 2009 16:49:23 +0100 From: Magnus Therning mag...@therning.org Subject: Re: [Haskell-beginners] SOLVED - Stack overflow, but hard to understand To: Michael Mossey m...@alumni.caltech.edu Cc: beginners@haskell.org Message-ID: e040b520910210849j4af70f45q540f57ffc3c63...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Wed, Oct 21, 2009 at 9:44 AM, Michael Mossey m...@alumni.caltech.edu wrote: Magnus Therning wrote: On 20/10/09 20:32, Michael Mossey wrote: Okay, I figured this out. mapM is not lazy, at least not for a monad that has state and under the circumstance you demand the state out the other side. If I understand what you are saying then this behaviour isn't unexpected.  If you have a monad with state, and you ask for the final state, then it's likely that everything happening in that particular monad will has to be evaluated. Hi Magnus, Yes, that's what I was trying to imply. I realized it is mathematically impossible for mapM to be lazy for a monad with state. mapM doesn't seem to be lazy anywhere. For example, this program main = do  buffers - forM [file1.txt,file2.txt,file3.txt] readFile  print . take 1 . concat $ buffers will, according to my experiments with the profiler, read all three files. It's possible to imagine lazy behavior here, but no doubt there is a technical reason against it. Laziness in combination with IO is a difficult thing. Just search the archives to see the number of threads about it. I may rewrite the program. Or I may consider the ISS principle. (Increase the stack, stupid.) You may also be able to improve the situation by adding a bit of strictness. In some cases the thunks resulting from laziness can take up a lot of space. Forcing evaluation, at well thought out locations in your program, may both speed things up and reduce memory/stack usage. You are probably right... I am having trouble spanning the gap between my current understanding and well thought-out locations. Real World Haskell has a chapter on this, so I may look there. I was able to get the program to run by removing all places that I had created a chain of Rand computations that forced evaluation of the last one. I replaced these with computations that did not require evaluation of the last one. However, my program was still forced to read more files than it really needed in the end, as the above snippet demonstrates. Just out of curiosity, did you verify that all three files were completely *read*, as opposed to all three opened, but only the first line of the first file being read? /M -- Magnus Therning(OpenPGP: 0xAB4DFBA4) magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org http://therning.org/magnus identi.ca|twitter: magthe -- Message: 2 Date: Wed, 21 Oct 2009 12:46:55 -0700 From: Michael Mossey m...@alumni.caltech.edu Subject: Re: [Haskell-beginners] SOLVED - Stack overflow, but hard to understand To: beginners beginners@haskell.org Message-ID: 4adf652f.3040...@alumni.caltech.edu Content-Type: text/plain; charset=UTF-8; format=flowed Magnus Therning wrote: Just out of curiosity, did you verify that all three files were completely *read*, as opposed to all three opened, but only the first line of the first file being read? /M Actually, no I didn't verify that, in this example. I was thinking about my other program in which I used mapM over the characters of the file onto a Rand monad. That one definitely read all the characters of the file---certain processing routines were called about 30,000 times (according to the profiler). This makes sense to me now, because I was asking for the state out the other side of the mapM. Thanks, Mike -- Message: 3 Date: Thu, 22 Oct 2009 12:11:07 -0700 (PDT) From:
Beginners Digest, Vol 16, Issue 18
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Caching evaluation of lazy lists (Philip Scott) 2. Re: Caching evaluation of lazy lists (Daniel Fischer) 3. RE: how to set command args in ghci (Kui Ma) 4. Re: Haskell Output Help (Chadda? Fouch?) 5. Re: how to set command args in ghci (Chadda? Fouch?) 6. Re: \x - x 0.5 x -0.5 (pl) 7. Re: Haskell Output Help (Brent Yorgey) 8. Re: \x - x 0.5 x -0.5 (Daniel Fischer) 9. Re: \x - x 0.5 x -0.5 (Darrin Thompson) -- Message: 1 Date: Fri, 23 Oct 2009 12:51:52 +0100 From: Philip Scott haskell-beginn...@foo.me.uk Subject: [Haskell-beginners] Caching evaluation of lazy lists To: beginners@haskell.org Message-ID: 4ae198d8.8090...@foo.me.uk Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi folks, Quick question for you. Suppose I have some lazy list, x, which is very expensive to evaluate, and I want to do something with it more than once; for example: f x = g (take 5 x) (take 6 x) Is Haskell clever enough to only evaluate the list as much as is needed, or will it evaluate it once to get the first five values, and again to get the first 6 (when really it only needed to get one more). Or is it really really clever, and works out it needs to take 6 to begin with, then just give you the first 5 for the first call? More tricky - is there a way to make that cache (if it exsists) persist in an interactive session? Eventually I am intending to write my own application with a little console at the bottom which does some ghci-esque magic, but for now lets say I am in ghci and I want to call f again with the same list. Is there a way to avoid it from forcing a recomputation of my lazy list? Any advice greatly appreciated, Philip -- Message: 2 Date: Fri, 23 Oct 2009 15:08:03 +0200 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] Caching evaluation of lazy lists To: beginners@haskell.org Message-ID: 200910231508.03578.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-1 Am Freitag 23 Oktober 2009 13:51:52 schrieb Philip Scott: Hi folks, Quick question for you. Suppose I have some lazy list, x, which is very expensive to evaluate, and I want to do something with it more than once; for example: f x = g (take 5 x) (take 6 x) Is Haskell clever enough to only evaluate the list as much as is needed, In that example, when you call f (makeExpensiveList arg1 arg2), the list is bound to the name x in the body of f, so g's arguments are taken from the very same list, which is evaluated only once. Each of the list elements is evaluated when it's needed, so maybe there will be fewer than 6 elements evaluated. However, if you call f (makeExpensiveList arg1 arg2) again later in the programme with the same arg1 and arg2, it will be probably evaluated again (the optimiser would need to see that it's called with the same arguments again and that it's worth caching the result to avoid that). If your expensive list is not generated by a function but a constant (like the list of Fibonacci numbers), bind it to a name expensiveList = ... and it will be cached between calls to f (unless memory pressure forces it to be garbage collected between calls and then re-evaluated). If it's generated by a function, give names to the lists obtained from frequently used arguments: exList_1_2 = makeExpensiveList 1 2 exList_4_0 = makeExpensiveList 4 0 ... cachedExpensiveList 1 2 = exList_1_2 cachedExpensiveList 4 0 = exList_4_0 ... cachedExpensiveList a b = makeExpensiveList a b or will it evaluate it once to get the first five values, and again to get the first 6 (when really it only needed to get one more). Or is it really really clever, and works out it needs to take 6 to begin with, then just give you the first 5 for the first call? The order of evaluation is determined by data-dependencies, so it may evaluate the list in order, or evaluate the sixth element first, then the first, after that the third,... More tricky - is there a way to make that cache (if it exsists) persist in an interactive session? Eventually I am intending to write my own application with a little console at the bottom which does some ghci-esque magic, but for now lets say I am in ghci and I want to call f again with the same list. Is there a way to avoid it from forcing a recomputation of my lazy list? Give it a name: let
Beginners Digest, Vol 16, Issue 19
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: \x - x 0.5 x -0.5 (Daniel Fischer) 2. Re: Haskell Output Help (Jan Jakubuv) 3. Re: Caching evaluation of lazy lists (Daniel Fischer) 4. Re: \x - x 0.5 x -0.5 (Darrin Thompson) 5. Re: [Haskell-cafe] Re: [Haskell-beginners] using quickcheck for blackbox testing for 3rd party apps. (Srikanth K) 6. random (John Moore) 7. Re: random (Brent Yorgey) 8. Re: random (Tom Davie) 9. Re: random (aditya siram) -- Message: 1 Date: Fri, 23 Oct 2009 17:32:29 +0200 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] \x - x 0.5 x -0.5 To: beginners@haskell.org Message-ID: 200910231732.29850.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-1 Am Freitag 23 Oktober 2009 17:25:57 schrieb Darrin Thompson: On Fri, Oct 23, 2009 at 10:25 AM, pl pl.lis...@gmail.com wrote: filter ((=0.5) . abs) xs pure () * ( 0.5) * ( -0.5) liftM2 () ( 0.5) ( -0.5) Someone suggested that this was an example of the reader monad but I don't get that. It's because ((-) r) *is* the reader monad. Control.Monad.Reader's Reader r a is just that wrapped in a newtype: newtype Reader r a = Reader { runReader :: r - a } :i (-) data (-) a b -- Defined in GHC.Prim instance Monad ((-) r) -- Defined in Control.Monad.Instances instance Functor ((-) r) -- Defined in Control.Monad.Instances instance Applicative ((-) a) -- Defined in Control.Applicative That's what I see working here. -- Darrin -- Message: 2 Date: Fri, 23 Oct 2009 16:42:48 +0100 From: Jan Jakubuv jaku...@gmail.com Subject: Re: [Haskell-beginners] Haskell Output Help To: Chandni Navani chandni...@yahoo.com Cc: beginners@haskell.org Message-ID: 20091023154248.ga8...@lxultra2.macs.hw.ac.uk Content-Type: text/plain; charset=iso-8859-1 Hi, seems to me like a job for `Text.PrettyPrint`: import Text.PrettyPrint ppString :: String - Doc ppString = doubleQuotes . text ppList :: [Doc] - Doc ppList = brackets . vcat . punctuate (text ,) pretty = ppList . map (ppList . map ppString) The code is hopefully almost self-explaining (`vcat` does the line breaking). The result looks as follows: *Main pretty [[abc, cde], [fgh, ghi]] [[abc, cde], [fgh, ghi]] Sincerely, jan. On Thu, Oct 22, 2009 at 12:11:07PM -0700, Chandni Navani wrote: I have a list of lists which all contain strings. [[String]]. I need to figure out how to print them so that after each individual string, there is a new line. If this is the initial list [[abc, cde] [fgh, ghi]] [[abc cde] [fgh, ghi]] Can anyone help me figure this out? Thanks. -- Heriot-Watt University is a Scottish charity registered under charity number SC000278. -- Message: 3 Date: Fri, 23 Oct 2009 19:34:44 +0200 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] Caching evaluation of lazy lists To: Philip Scott psc...@foo.me.uk Cc: beginners@haskell.org Message-ID: 200910231934.44610.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-1 Am Freitag 23 Oktober 2009 18:30:53 schrieb Philip Scott: Hello again, then, barring memory pressure forcing it out, it will be computed only once (each list element will be computed only once, when it's first needed). Thanks Daniel, that was what I was after. Is there any way of investigating these things without using the profiler? E.g. is there any way to stick a debug print statement inside a function without moving over to sideeffects and IO Monads etc.. I know printing is a side effect, but it would be nice to say 'I can has itsy sneeky side effect plz Haskell, just for little testing while' Cheers, Philip import Debug.Trace infixl 0 `debug` debug = flip trace dfib :: Int - Integer dfib = let fib 0 = 0 fib 1 = 1 fib n = dfib (n-2) + dfib (n-1) `debug` eval fib ++ show n in (map fib [0 .. ] !!) Ok, modules loaded: MFib. *MFib dfib 4 eval fib 4 eval fib 2 eval fib 3 3 *MFib dfib 7 eval fib 7 eval fib 5 eval fib 6 13 *MFib dfib 15 eval fib 15 eval fib 13 eval fib 11 eval fib 9 eval fib 8 eval fib 10 eval fib 12 eval fib 14 610 *MFib The trick with debug = flip trace makes commenting out the debug-code easier: fun x = trace (fun ++ show x) $ body x ~ fun x = {- trace (fun ++ show x) $ -} body x vs.
Beginners Digest, Vol 16, Issue 26
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Chessboard Module, opinions on? (i?fai) 2. Re: Chessboard Module, opinions on... (Christian Maeder) 3. Memoization (Shawn Willden) 4. Re: Memoization (Daniel Fischer) 5. Re: Chessboard Module, opinions on? (Andy Elvey) 6. Re: Chessboard Module, opinions on? (Andy Elvey) 7. list monad question (Matthias Guedemann) 8. Re: list monad question (David Virebayre) 9. Re: list monad question (Jan Jakubuv) -- Message: 1 Date: Wed, 28 Oct 2009 11:23:31 -0400 From: i?fai iae...@me.com Subject: Re: [Haskell-beginners] Chessboard Module, opinions on? To: Darrin Thompson darri...@gmail.com Cc: Beginners@haskell.org Message-ID: 10bde766-a51e-44fd-903b-bc6c9085f...@me.com Content-Type: text/plain; charset=iso-8859-1; format=flowed; delsp=yes If I had a clock, I would consider it :P On 2009-10-28, at 11:20 AM, Darrin Thompson wrote: On Wed, Oct 28, 2009 at 2:33 AM, iæfai iae...@me.com wrote: The chess AI process is something I still have to hunt for mind you, but the part that is the most interesting is that I am going to be controlling a $50,000 robot with this in class :P. For $50k do you get a robot that can play a serious intimidating blitz? Can it smack the clock with Class A player _authority_? :-) -- Darrin -- Message: 2 Date: Wed, 28 Oct 2009 17:01:29 +0100 From: Christian Maeder christian.mae...@dfki.de Subject: [Haskell-beginners] Re: Chessboard Module, opinions on... To: i?fai iae...@me.com Cc: Beginners@haskell.org Message-ID: 4ae86ad9.6000...@dfki.de Content-Type: text/plain; charset=ISO-8859-1 iæfai schrieb: Andy, feel free. I should note that I am going to update this code to use Text.PrettyPrint.HughesPJ shortly. In addition, it will be Using a pretty printer library for this fixed format seems unnecessary to me. C. -- Message: 3 Date: Wed, 28 Oct 2009 19:45:35 -0600 From: Shawn Willden shawn-hask...@willden.org Subject: [Haskell-beginners] Memoization To: beginners@haskell.org Message-ID: 200910281945.35769.shawn-hask...@willden.org Content-Type: text/plain; charset=us-ascii Hi, I've just begun experimenting with Haskell, and I'm having a lot of fun, but my first semi-serious program is in need of some optimization, and based on the results of profiling I think a really good start is to memoize one particular function which is called many, many times (and currently consumes over 80% of the program run time). The function takes a two-dimensional range and a location within that range and returns a list of the locations vertically and horizontally adjacent to that location and within the bounds type Bounds = ((Int,Int),(Int,Int)) type Location = (Int,Int) adjacentCells :: Bounds - Location - [Location] adjacentCells bounds (col, row) = filter valid cells where valid loc = inRange bounds loc neighborLoc' = [(col-1,row),(col+1,row),(col,row-1),(col,row+1)] The ranges are fairly small -- certainly no more than 10x10, and each location has an associated list of at most 4 neighbors (edge locations have less). During a given run of the program, the bounds are fixed. So, any tips on how I can memoize this function? I have read the Memoization page on the wiki, and I understand (I think) the recursive memoization section, but it's not clear to me how to apply that approach. Section one on non-recursive memoization seems like what I want, but I don't understand the section and the links provided haven't shed any light for me. The section uses the following notation to describe how to construct a map to be used to hold the keys and values: Map ()b := b Map (Either a a') b := (Map a b, Map a' b) Map (a,a')b := Map a (Map a' b) but I'm not sure what that notation is. It's not Haskell code, I don't think. Any and all suggestions appreciated. Thanks, Shawn. -- Message: 4 Date: Thu, 29 Oct 2009 03:20:43 +0100 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] Memoization To: beginners@haskell.org Message-ID: 200910290320.44286.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-1 Am Donnerstag 29 Oktober 2009 02:45:35 schrieb Shawn Willden: Hi, I've just begun experimenting with Haskell, and I'm having a lot of fun, but my first semi-serious program is in need of some
Beginners Digest, Vol 16, Issue 27
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: list monad question (David Virebayre) 2. Re: list monad question (David Virebayre) 3. Re: list monad question (Matthias Guedemann) 4. Re: list monad question (Daniel Fischer) 5. Re: list monad question (Matthias Guedemann) 6. Re: list monad question (Matthias Guedemann) 7. Re: list monad question (Matthias Guedemann) 8. beginner question (Luca Ciciriello) 9. Re: list monad question (Ertugrul Soeylemez) 10. Re: Re: list monad question (Matthias Guedemann) -- Message: 1 Date: Fri, 30 Oct 2009 13:29:20 +0100 From: David Virebayre dav.vire+hask...@gmail.com Subject: Re: [Haskell-beginners] list monad question To: Matthias Guedemann matthias.guedem...@ovgu.de Cc: beginners beginners@haskell.org Message-ID: 4c88418c0910300529h2ef4cd1eib5e2c13e0b3f8...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Fri, Oct 30, 2009 at 1:09 PM, David Virebayre dav.vire+hask...@gmail.com wrote: Almost there : Nevermind, I didn't read the question carefully Sorry about that :( -- Message: 2 Date: Fri, 30 Oct 2009 13:36:21 +0100 From: David Virebayre dav.vire+hask...@gmail.com Subject: Re: [Haskell-beginners] list monad question To: Matthias Guedemann matthias.guedem...@ovgu.de Cc: beginners beginners@haskell.org Message-ID: 4c88418c0910300536p75b38a50k629b60aef643e...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Fri, Oct 30, 2009 at 12:44 PM, Matthias Guedemann matthias.guedem...@ovgu.de wrote: Now I want to make it capable to create all combinations of length n instead of fixed length 3 (that's why list instead of tuple), but I don't really see how. If I understood what you ask this time, there's a function in Control.Monad that does it : allN = replicateM replicateM 4 [ 1,2,3 ] = [ [ 1,1,1,1],[1,1,1,2], when you write a - ls b - ls c - ls You perform the monad action 3 times, collecting the result in a then b, then c. now replicateM performs a monad action n times, collecting the result in a list. turns out that making a list of the result is exactly what you want. David. -- Message: 3 Date: Fri, 30 Oct 2009 13:37:55 +0100 From: Matthias Guedemann matthias.guedem...@ovgu.de Subject: Re: [Haskell-beginners] list monad question To: David Virebayre dav.vire+hask...@gmail.com Cc: beginners beginners@haskell.org Message-ID: 1256906197-sup-9...@pc44es141.cs.uni-magdeburg.de Content-Type: text/plain; charset=UTF-8 Thanks David, all3 ls = do a - ls b - ls c - ls return (a,b,c) For each element a of list ls , for each element b of the same list ls, and for each element c of the same list ls, make a tuple of them. return the list of tall the tuples. But it is a bit more complicated. I changed the result to [a,b,c] in order to have variable length results. I am now trying to get a allN ls n function that returns the result for the original problem with allN [0..5] 3 and all combinations of the form [a,b] with allN [0..5] 2. So basically I want a variable number of name bindings in the list comprehension. Is this possible in a (simple) way using the list monad? Maybe like allN ls n = foldr (=) [] (replicate n ls) = return regards, Matthias -- __ ___ ____ Dipl. Inf. Matthias Guedemann / __\/ _\ /__\ Computer Systems in Engineering / / \ \ /_\ Otto-von-Guericke Universitaet Magdeburg / /___ _\ \//__ Tel.: 0391 / 67-19359\/ \__/\__/ __ -- Message: 4 Date: Fri, 30 Oct 2009 13:56:34 +0100 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] list monad question To: beginners@haskell.org Message-ID: 200910301356.34688.daniel.is.fisc...@web.de Content-Type: text/plain; charset=utf-8 Am Freitag 30 Oktober 2009 12:44:41 schrieb Matthias Guedemann: Hi, a friend of mine wanted to write function (in Perl) that creates all tuples of length 3 of the elements of a given list, e.g. [(0,0,0),(0,0,1),(0,0,2),...,(5,5,5)] for the list [0..5]. Trying to get better at Haskell, I wrote a small function using the list monad for this (tuples replaced with lists) all3 ls = do a - ls b - ls c - ls return [a,b,c] Now I
Beginners Digest, Vol 16, Issue 28
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: beginner question (Daniel Fischer) 2. Re: list monad question (Daniel Fischer) 3. Re: beginner question (Shawn Willden) 4. Re: list monad question (Matthias Guedemann) 5. RE: beginner question (Luca Ciciriello) 6. Re: list monad question (Colin Paul Adams) 7. Re: list monad question (Stephen Tetley) 8. Re: beginner question (Brent Yorgey) 9. Re: list monad question (Daniel Fischer) -- Message: 1 Date: Fri, 30 Oct 2009 15:46:33 +0100 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] beginner question To: beginners@haskell.org Message-ID: 200910301546.34301.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-15 Am Freitag 30 Oktober 2009 14:40:13 schrieb Luca Ciciriello: Hi all. Just a very basic question. I need to write a function str2lsts :: String - [[String]] in order to transorm a string like: \1\,\cat\,\dog\§\2\,\duck\,\goose\ in the list of lists: [[1,cat,dog],[2,duck,goose]] I've tried to mix recursion, pattern matching and list comprehension, but the obtained result was embarrassing complex ( 20 lines of awful code). I think that a more simple solution certainly exists. splitOnToken :: Eq a = a - [a] - [[a]] splitOnToken t xs = case break (== t) xs of (hd,tl) - hd:case tl of (_:r@(_:_)) - splitOnToken t r _ - [] str2lsts = map (map read . splitOnToken ',') . splitOnToken '§' if things weren't enclosed in quotation marks inside the string, it would be the nicer map (splitOnToken ',') . splitOnToken '§' , provided of course, neither ',' nor '§' are valid characters for the target strings. import Text.ParserCombinators.Parsec simple = between (char '') (char '') (many (staisfy (/= ''))) -- alternative: simple = char '' manyTill anyChar (char '') multiple = sepBy simple (char ',') total = sepBy multiple (char '§') str2lsts str = case parse total str of Left err - error (show err) Right lsts - lsts Thanks in advance for any idea. Luca -- Message: 2 Date: Fri, 30 Oct 2009 16:03:37 +0100 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] list monad question To: Matthias Guedemann matthias.guedem...@ovgu.de Cc: beginners beginners@haskell.org Message-ID: 200910301603.37963.daniel.is.fisc...@web.de Content-Type: text/plain; charset=utf-8 Am Freitag 30 Oktober 2009 14:32:35 schrieb Matthias Guedemann: Hi Daniel, That gives combinations n xs = foldr f [[]] (replicate n xs) pointfree, for extra goodness: -- pointfree f inline combinations n xs = foldr ((. (. (:)) . flip map) . (=)) [[]] (replicate n xs) -- eliminate xs combinations n = foldr ((. (. (:)) . flip map) . (=)) [[]] . replicate n -- completely pointfree combinations = (foldr ((. (. (:)) . flip map) . (=)) [[]] .) . replicate thank you, looks rather strange to me but works well. Yes :D The pointfree f is nicely obfuscated. But if your friend is a perl coder, he should be able to appreciate that. The standard way to express f, however, is liftM2 (:), so combinations = (foldr (liftM2 (:)) [[]] .) . replicate -- isn't that boring? But earnestly, replicateM is the thing to use. regards -- Message: 3 Date: Fri, 30 Oct 2009 09:11:48 -0600 From: Shawn Willden shawn-hask...@willden.org Subject: Re: [Haskell-beginners] beginner question To: beginners@haskell.org Message-ID: 200910300911.48668.shawn-hask...@willden.org Content-Type: text/plain; charset=utf-8 On Friday 30 October 2009 07:40:13 am Luca Ciciriello wrote: I need to write a function str2lsts :: String - [[String]] in order to transorm a string like: \1\,\cat\,\dog\§\2\,\duck\,\goose\ in the list of lists: [[1,cat,dog],[2,duck,goose]] A variety of solutions on these blog posts, and the comments: http://gimbo.org.uk/blog/2007/04/20/splitting-a-string-in-haskell/ http://julipedia.blogspot.com/2006/08/split-function-in-haskell.html Shawn. -- Message: 4 Date: Fri, 30 Oct 2009 16:34:13 +0100 From: Matthias Guedemann matthias.guedem...@ovgu.de Subject: Re: [Haskell-beginners] list monad question To: Daniel Fischer daniel.is.fisc...@web.de Cc: beginners beginners@haskell.org Message-ID: 1256916789-sup-...@pc44es141.cs.uni-magdeburg.de Content-Type:
Beginners Digest, Vol 16, Issue 29
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. hierarchy of modules (Michael Mossey) 2. Re: hierarchy of modules (Daniel Fischer) 3. Class definition syntax (Shawn Willden) 4. Re: Class definition syntax (Joe Fredette) 5. Re: hierarchy of modules (Steven Cummings) 6. Re: Class definition syntax (Daniel Fischer) 7. Re: hierarchy of modules (Michael Mossey) 8. Re: hierarchy of modules (Daniel Fischer) -- Message: 1 Date: Sat, 31 Oct 2009 05:32:51 -0700 From: Michael Mossey m...@alumni.caltech.edu Subject: [Haskell-beginners] hierarchy of modules To: beginners@haskell.org Message-ID: 4aec2e73.6000...@alumni.caltech.edu Content-Type: text/plain; charset=ISO-8859-1; format=flowed I want to have a hierarchy of modules for a local project. Not submitting it to Hackage yet. I just want to refer to my local modules as Basics.CSound Basics.Node Algo.Fux etc. how does one set this up? Thanks, Mike -- Message: 2 Date: Sat, 31 Oct 2009 13:54:31 +0100 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] hierarchy of modules To: beginners@haskell.org Message-ID: 200910311354.31475.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-1 Am Samstag 31 Oktober 2009 13:32:51 schrieb Michael Mossey: I want to have a hierarchy of modules for a local project. Not submitting it to Hackage yet. I just want to refer to my local modules as Basics.CSound Basics.Node Algo.Fux etc. how does one set this up? Top directory: project.cabal, Setup.hs (module Main where main = defaultMain) Subdirectry Basics: File CSound.hs (module Basics.CSound (exports) where...) File Node.hs (module Basics.Node (exports where...) Subdirectory Algo: File Fux.hs (module Algo.Fux (exports) where...) cd Top directory cabal install Thanks, Mike -- Message: 3 Date: Sat, 31 Oct 2009 10:27:10 -0600 From: Shawn Willden shawn-hask...@willden.org Subject: [Haskell-beginners] Class definition syntax To: beginners@haskell.org Message-ID: 200910311027.10559.shawn-hask...@willden.org Content-Type: text/plain; charset=us-ascii I have a program that makes use of various data types built on top of Arrays. In some cases, they're data types that contain an Array plus some additonal information, in others, they're just newtype Arrays, so that I can use typechecking to make sure that I'm not using the wrong kind of object. I'd really like to define an ArrayOps class with all of the operations I need, and define instances for all of the specific types. I also use some raw Array objects, so it would be even better if I could make an instance of my class for Array. And, ideally, I'd like to use the Array operations for my class operations. So, I want something like: class ArrayOps a where (!):: a - i - e (//) :: a - (i,e) - a bounds :: a - (i,i) range :: a - [i] 'i' and 'e' are the index and element types, respectively. Obviously, the signatures above reference type variables that aren't declared, and really must be constrained to be the 'i' and 'e' that were used in building the type 'a' (which is an Array i e). Something like the following (though this obviously doesn't work): class ((Array.Array i e) a) = ArrayOps a where ... I'm sure there must be a way to do this, but I can't figure out what the syntax would look like. Thanks, Shawn. -- Message: 4 Date: Sat, 31 Oct 2009 12:33:10 -0400 From: Joe Fredette jfred...@gmail.com Subject: Re: [Haskell-beginners] Class definition syntax To: Shawn Willden shawn-hask...@willden.org Cc: beginners@haskell.org Message-ID: 17d619c7-3d98-4190-bc9d-73575c75f...@gmail.com Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes You'll probably need to look at associated types/functional dependencies. The former is the new hotness, the latter is the old and not-so-busted. A quick search of the wiki ought to reveal much more than I can possibly explain, there is an example on the page for Assoc. Types about generic Map implementation, which is similar to what you're trying to do. On Oct 31, 2009, at 12:27 PM, Shawn Willden wrote: I have a program that makes use of various data types built on top of Arrays. In some cases, they're data types that contain an Array plus some additonal information, in others, they're just newtype
Beginners Digest, Vol 16, Issue 30
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: hierarchy of modules (Stephen Tetley) 2. Ord [] instance (Keith Sheppard) 3. Re: Ord [] instance (Daniel Fischer) 4. Re: Ord [] instance (Keith Sheppard) 5. Re: Class definition syntax (Shawn Willden) 6. Re: Class definition syntax (Shawn Willden) 7. Re: Class definition syntax (Shawn Willden) 8. Re: Class definition syntax (Joe Fredette) 9. Re: Class definition syntax (Shawn Willden) -- Message: 1 Date: Sat, 31 Oct 2009 19:33:53 + From: Stephen Tetley stephen.tet...@gmail.com Subject: Re: [Haskell-beginners] hierarchy of modules To: Michael Mossey m...@alumni.caltech.edu Cc: beginners beginners@haskell.org Message-ID: 5fdc56d70910311233w2cbfd9f6v9f80c8f7adc5a...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 Hello Mike An option I like is to put the main project files in a top level directory called src, so your organization would look like this: ./src/Algo/Fux.hs ./src/Basics/CSound.hs ./src/Basics/Node.hs I usually have a running example which has imports for all the files in the project inside a top level folder called demo... ./demo/ImportAll.hs For a GHCi session, I cd to $PROJECT/demo then ghci Prelude set -i../src This is the useful bit of having all the project files under the src hierarchy - the search path is very simple. During development adding the files needed for cabal (Setup.hs, project.cabal...) is still worthwhile - you can then generate Haddock docs very easily. If you used Haddock in standalone mode you would have to supply a few flags to tell which files to document and where to put the output. Each time you add or remove a module in the src tree, you should re-run configure... runhaskell Setup.hs configure runhaskell Setup.hs haddock but as your GHCi session is always using the interpreted project source you don't need to run 'runhaskell Setup.hs build' and 'runhaskell Setup.hs install'. Best wishes Stephen -- Message: 2 Date: Sat, 31 Oct 2009 15:39:57 -0400 From: Keith Sheppard keiths...@gmail.com Subject: [Haskell-beginners] Ord [] instance To: beginners@haskell.org Message-ID: 92e42b740910311239pf614067w9eebcd51c7db2...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 the compare function for lists seems to be work like (leaving off class details): compare [] [] = EQ compare [] _ = LT compare _ [] = GT compare (x:xt) (y:yt) = case x `compare` y of EQ - xt `compare` yt _ - x `compare` y I poked around to see if I could find where this was defined in the spec or if it was an implementation specific thing (I need to be able to rely on this definition across implementations). I found this text in the report: -- Lists data [a] = [] | a : [a] deriving (Eq, Ord) -- Not legal Haskell; for illustration only Is this basically saying the same thing as my compare definition? Thanks Keith -- keithsheppard.name -- Message: 3 Date: Sat, 31 Oct 2009 21:01:46 +0100 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] Ord [] instance To: beginners@haskell.org Message-ID: 200910312101.46296.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-1 Am Samstag 31 Oktober 2009 20:39:57 schrieb Keith Sheppard: the compare function for lists seems to be work like (leaving off class details): compare [] [] = EQ compare [] _ = LT compare _ [] = GT compare (x:xt) (y:yt) = case x `compare` y of EQ - xt `compare` yt _ - x `compare` y I poked around to see if I could find where this was defined in the spec or if it was an implementation specific thing (I need to be able to rely on this definition across implementations). You can rely on lexicographic ordering for lists. Haskell Report, section 10.1 ( http://haskell.org/onlinereport/derived.html#derived- appendix ): 10.1 Derived instances of Eq and Ord The class methods automatically introduced by derived instances of Eq and Ord are (==), (/=), compare, (), (=), (), (=), max, and min. The latter seven operators are defined so as to compare their arguments lexicographically with respect to the constructor set given, with earlier constructors in the datatype declaration counting as smaller than later ones. I found this text in the report: -- Lists data [a] = [] | a : [a] deriving (Eq, Ord) -- Not legal Haskell; for
Beginners Digest, Vol 17, Issue 1
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. ErrorT Identity (Michael Mossey) 2. Re: Class definition syntax (Joe Fredette) 3. Re: Class definition syntax (Daniel Fischer) 4. several questions: multi-param typeclasses, etc. (Michael Mossey) 5. Re: several questions: multi-param typeclasses, etc. (Brent Yorgey) 6. Re: several questions: multi-param typeclasses,etc. (Michael Mossey) 7. Re: several questions: multi-param typeclasses, etc. (Brent Yorgey) 8. Re: several questions: multi-param typeclasses, etc. (Chadda? Fouch?) -- Message: 1 Date: Sat, 31 Oct 2009 20:48:48 -0700 From: Michael Mossey m...@alumni.caltech.edu Subject: [Haskell-beginners] ErrorT Identity To: beginners@haskell.org Message-ID: 4aed0520.3060...@alumni.caltech.edu Content-Type: text/plain; charset=ISO-8859-1; format=flowed Does using ErrorT Identity have advantages over Either? -Mike -- Message: 2 Date: Sat, 31 Oct 2009 23:53:16 -0400 From: Joe Fredette jfred...@gmail.com Subject: Re: [Haskell-beginners] Class definition syntax To: Shawn Willden shawn-hask...@willden.org Cc: beginners@haskell.org Message-ID: 992836ac-4c2b-45b1-8aea-8809989c2...@gmail.com Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Ahh, I see what you need, you want to lift the IArray functions into your type. Well, Rather than trying to instance the type- you could define your type like this: newtype Board = Board IArray.IArray ... whatever (!) :: Board - Location - Int (!) = IArray.(!) That is, create synonyms manually for each function you _absolutely need, assuming they don't conflict elsewhere. You would have to manually import each -- I feel like there is probably a better way to do this, but this will definitely work. Though, I'm not sure why you'd need to be instancing another class with a type like this, it's a _very_ specific type, I imagine one or the other set of functions ought to be easy enough to define simply about the type (dodging the typeclass entirely). I imagine extensibility comes to play here. One thing you might be able to do is class IArray a Location Int , OtherClass a ... = MyClass a ... where Which would force you to have a type which is an IArray of Location - Ints, and an OtherClass, etc. I don't know all the details of your implementation, so I don't know how well this would work, but I imagine thats probably the better solution I'm thinking of... /Joe On Oct 31, 2009, at 11:42 PM, Shawn Willden wrote: On Saturday 31 October 2009 08:55:56 pm Joe Fredette wrote: Well, I think the issue is you're thinking too OOPy... I understand what you're saying, but I don't think I am. But let me answer the actual problem first, type classes are (basically) functions on types. So a type of kind `* - * - *` means it is a type which accepts two type variables. So: newtype Foo a b = Foo (a, b) Okay, that makes sense. What I'd read about kinds was considerably less clear. Thanks. newtype Board = Board IArray ... means that _you can just use the IArray types_! Well, almost, really what you want is a type-synonym: type Board = IArray Location ... Now you can write functions like foo :: Board - Int foo = Board !! (1,2) and it will just work because Board _is_ an IArray. Hope that makes sense... It does make sense, but it doesn't solve my problem. See, Board isn't the only type I have (and, also, Board has to be a newtype rather than a type synonym because it's also an instance of another class -- well, unless I want to turn on the extension that allows instances of synonyms, and I'm not sure what the etiquette is there), and some of the others aren't just IArrays with an aliased name, they have other data elements as well. For example: data ScoredBoard = ScoredBoard { arry :: (IArray Location String) score:: Int maxScore :: Int } I would like to be able to use (!), (//), bound, range, etc., on those as well, and without having to say range (arry sb), or having to define a bunch of fooRange, barRange, bazRange, etc., functions. Basically I want to take this set of common array operations and overload them for a bunch of different types. As I understand it, classes are effectively the only way to overload in Haskell.
Beginners Digest, Vol 17, Issue 3
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Multiple type numeric data (David Virebayre) 2. Re: I have created an ugly Haskell program.. (Michael Mossey) 3. Re: I have created an ugly Haskell program.. (Philip Scott) 4. Re: I have created an ugly Haskell program.. (Michael Mossey) 5. Re: Error Handling and case statements (Daniel Fischer) 6. Re: I have created an ugly Haskell program.. (Brent Yorgey) 7. Finding documentation when Hackage is down. (aditya siram) 8. Re: Finding documentation when Hackage is down. (Michael Lesniak) -- Message: 1 Date: Mon, 2 Nov 2009 10:51:43 +0100 From: David Virebayre dav.vire+hask...@gmail.com Subject: Re: [Haskell-beginners] Multiple type numeric data To: beginners@haskell.org Message-ID: 4c88418c0911020151m678519dbv2231373544c94...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 2009/11/2 David Virebayre dav.vire+hask...@gmail.com: Salut, ton problème c'est que la valeur de retour de surface_rond est float, mais le rayon est integer. [...] Sorry for the post in French to the list, I thought Didier might like a reply in French but I didn't mean to post it to the list also. -- Message: 2 Date: Mon, 02 Nov 2009 02:22:09 -0800 From: Michael Mossey m...@alumni.caltech.edu Subject: Re: [Haskell-beginners] I have created an ugly Haskell program.. To: Philip Scott haskell-beginn...@foo.me.uk Cc: beginners@haskell.org Message-ID: 4aeeb2d1.2080...@alumni.caltech.edu Content-Type: text/plain; charset=ISO-8859-1; format=flowed Function you seek is 'specialZip' below. 'fluff' and 'decapitate' are helpers. Not extensively tested. -- Given a list of ints that should all have values, fill in missing -- values using the last value as default. fluff :: String - [Int] - [(Int,String)] - [(Int,String)] fluff last (i:is) pss@((t,s):ps) | i == t = (i,s) : fluff s is ps | i t = (i,last) : fluff last is pss fluff last is [] = zip is (repeat last) -- Given two lists, remove enough from the front to get to two equal keys. decapitate [] _ = ([],[]) decapitate _ [] = ([],[]) decapitate xss@((tx,_):xs) yss@((ty,_):ys) | tx ty = decapitate xs yss | ty tx = decapitate xss ys | ty == tx = (xss,yss) specialZip d1 d2 = let (dd1,dd2) = decapitate d1 d2 -- build set of every key that should be in final list s = S.toAscList . S.fromList $ (map fst dd1) ++ (map fst dd2) in case (dd1,dd2) of ([],[]) - [] (xs1,xs2) - let f1 = fluff s xs1 -- use this set to fluff f2 = fluff s xs2 -- each list -- so final answer can be a simple zipWith in zipWith (\(t1,s1) (t2,s2) - (t1,(s1,s2))) f1 f2 Philip Scott wrote: .. and I am positive there must be a way of beautifying it, but I am struggling. I bet there is just some lovely way of making this all shrink to three lines.. So here's the problem. I have two lists of tuples: (timestamp, value) What I would like to do in do a kind of 'zip' on two of these lists to make a list of (timestamp, (value1, value2)) with the following rules: - If the timestamps are equal it's easy - make your new element an move on - If one of the lists has a timestamp that the other doesn't, repeat an old value from the other list - If we don't have an old value yet, then don't create an element in the new list. e.g. if I ran my algorithm on these two lists d1 = [ (1,a), (2,b), (3,c) ] d2 = [ (2,b'), (4,d') ] I would like to get result = [ (2, (b,b')), (3, (c,b')), (4, (c,d')) ] e.g. there was no data in d2 for our first element so we skipped it. Okay, so here is my code.. It works, but makes me feel a bit dirty. To explain my nomenclature 't' is 'timestamp of', 'v' is 'value of'. vx' and vy' are the 'old' values from the previous iteration in case a repeat is needed. They are Maybes because at the beginning there may be no old value. d1 = [ (1,a), (2,b), (3,c) ] d2 = [ (2,b'), (4,d') ] t (x,y) = x v (x,y) = y js vx' vy' (x:xs) (y:ys) | t x == t y = ( (t x), (v x, v y) ) : js (Just (v x)) (Just (v y)) xs ys | t x t y = maybe (js (Just (v x)) Nothing xs (y:ys)) (\z - ( t x, (v x, z ) ) : ( js (Just (v x)) (Just z) xs (y:ys))) vy' | t x t y = maybe (js Nothing
Beginners Digest, Vol 17, Issue 5
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: I have created an ugly Haskell program.. (Heinrich Apfelmus) 2. Does System.Directory work on Windows XP? (Patrick Larrivee-Woods) 3. Re: Does System.Directory work on Windows XP? (Jason Dusek) 4. Re: Does System.Directory work on Windows XP? (Patrick Larrivee-Woods) 5. Re: Does System.Directory work on Windows XP? (Daniel Fischer) 6. Lazy file IO Space leaks/waste (Aleksandar Dimitrov) 7. if ands (Nathan M. Holden) 8. Re: if ands (Joe Fredette) 9. Re: if ands (Keith Sheppard) -- Message: 1 Date: Wed, 04 Nov 2009 18:21:17 +0100 From: Heinrich Apfelmus apfel...@quantentunnel.de Subject: [Haskell-beginners] Re: I have created an ugly Haskell program.. To: beginners@haskell.org Message-ID: hcsd6d$vv...@ger.gmane.org Content-Type: text/plain; charset=ISO-8859-1 Brent Yorgey wrote: Ask yourself: What Would Conal Do (WWCD)? Conal Elliott is always trying to get people to think about the semantic essence of their problems, so let's try it. What are we REALLY trying to do here? What are those lists of tuples, REALLY? Well, it seems to me that the lists of tuples are really just representing *functions* on some totally ordered domain. [...] So, let's try converting these lists of pairs to actual functions: asFunc :: (Ord a) = [(a,b)] - (a - Maybe b) asFunc is a = fmap snd . listToMaybe . reverse . takeWhile ((=a) . fst) $ is [...] Now, you might object that this is much more inefficient than the other solutions put forth. That is very true. [...] However, I still find it very helpful to think about the essence of the problem like this: elegant yet inefficient code is a much better starting place than the other way around! [...] You can also try to optimize, taking advantage of the fact that we always call the functions built by asFunc with a sequence of strictly increasing inputs. I am with Brent and Conal here. Now, to continue, ask yourself: What Would Conal Do Next (WWCDN)? What are we really trying to do here? What is this function, really, considering that we are only evaluating it at a strictly increasing sequence of inputs? Well, it seems to me that it is some special kind of function, best captured as an *abstract data type*. In particular, the function is something which I will call a time series. In other words, the input is to be thought of as time. data Time t = Moment t | Infinity deriving (Eq,Ord,Show) The inclusion of infinity will turn out to be very convenient. Now, the time series is a function that has a value x1 in the distant past, until a time t1 where it begins to have the value x2 , again until a time t2 where it switches to x3 and so on, until a value xn that is kept until infinity. In Haskell, this looks like this function t | -Infinity = t t t1 = x1 |t1 = t t t2 = x2 |t2 = t t t3 = x3 | ... |t1 = t t Infinity = xn and pictorially, something like this: xn _ x2 | || x3 ... | _ x1 | -Inf t1t2 ... tn Inf Of course, we can implement this abstract data type with a list of pairs (tk,xk) newtype TimeSeries t a = TS { unTS :: [(a,Time t)] } deriving (Show) and our goal is to equip this data type with a few natural operations that can be used to implement Philip's zip-like function. The first two operations are progenitor :: TimeSeries t a - a progenitor = fst . head . unTS which returns the value from the distant past and beginning :: TimeSeries t a - Time t beginning = snd . head . unTS which returns the first point in time when the function changes its value. These correspond to the operation head on lists. The next operation is called `forgetTo` t and will throw away all values and changes before and including a given time t . forgetTo :: Ord t = TimeSeries t a - Time t - TimeSeries t a forgetTo (TS xs) Infinity = TS [last xs] forgetTo (TS xs) t= TS $ dropWhile ((= t) . snd) xs This roughly corresponds to tail , but takes advantage of the time being continuous. Last but not least, we need a way to create a time series forever ::
Beginners Digest, Vol 17, Issue 6
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. N-ary tree search problems (Ryan Temple) 2. Re: N-ary tree search problems (i?fai) 3. Show Floats (Nathan M. Holden) 4. Re: Show Floats (i?fai) 5. re: Show Floats (Nathan M. Holden) 6. Re: Show Floats (David Virebayre) 7. Re: Show Floats (Johannes Laire) 8. Re: if ands (Deniz Dogan) 9. Re: N-ary tree search problems (Stephen Tetley) -- Message: 1 Date: Wed, 4 Nov 2009 12:04:08 + From: Ryan Temple ryantemple...@googlemail.com Subject: [Haskell-beginners] N-ary tree search problems To: beginners@haskell.org Message-ID: 33ff8d520911040404h2db6f4c8k473e1b87e2b35...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 I'm making a general purpose N-ary tree and im coming up with unexpected '=' on line 17 as an error. I have spent a fair while trying to work out why this isn't accepting the case that an Empty gtree returns false for any member search. i realise this is probably a very trivial error but any help would be appreciated: module GTrees where data Gtree = Empty | Leaf String | Node String [Gtree] deriving (Show) --Tests if a given string is a member of the tree gtreeMember :: (Ord a) = a - Gtree a - Bool gtreeMember y Empty = False -- line 17 gtreeMember y (Leaf x) = (x==y) gtreeMember y (Node x tree) |x==y = True |otherwise gtreeMember tree This is the code up to the point of the error with the error line highlighted -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20091104/18de551b/attachment-0001.html -- Message: 2 Date: Thu, 05 Nov 2009 22:10:04 -0500 From: i?fai iae...@me.com Subject: Re: [Haskell-beginners] N-ary tree search problems To: Ryan Temple ryantemple...@googlemail.com Cc: Beginners@haskell.org Message-ID: e9a2eaca-4a80-4d8b-be1a-a22c96db8...@me.com Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Try to make sure things are lined up properly, like the Empty and Left, and why are some gtreeMember indented? On 2009-11-04, at 7:04 AM, Ryan Temple wrote: I'm making a general purpose N-ary tree and im coming up with unexpected '=' on line 17 as an error. I have spent a fair while trying to work out why this isn't accepting the case that an Empty gtree returns false for any member search. i realise this is probably a very trivial error but any help would be appreciated: module GTrees where data Gtree = Empty | Leaf String | Node String [Gtree] deriving (Show) --Tests if a given string is a member of the tree gtreeMember :: (Ord a) = a - Gtree a - Bool gtreeMember y Empty = False -- line 17 gtreeMember y (Leaf x) = (x==y) gtreeMember y (Node x tree) |x==y = True |otherwise gtreeMember tree This is the code up to the point of the error with the error line highlighted ___ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners -- Message: 3 Date: Fri, 6 Nov 2009 00:31:05 -0500 From: Nathan M. Holden nathanmhol...@gmail.com Subject: [Haskell-beginners] Show Floats To: beginners@haskell.org Message-ID: 200911060031.05956.nathanmhol...@gmail.com Content-Type: Text/Plain; charset=us-ascii I have been working on a small library that will typeset notes in LaTeX for me, since I tend to have haphazard typesetting while I write, but while I read I like to have standards. Anyways, I defined a datatype data Color = RGB { name :: [Char], r :: Float, g :: Float, b :: Float, matchText :: [[Char]], targetText :: [Char]} deriving(Show,Eq,Read) I wanted to be able to have a piece of code that said \\definecolor{++name++}{rgb}{++show r++,++show g++,++show b++} but because I have numbers below 0.1, it outputs as 2.0e-2, which is useless. I wrote a function that would output useful numbers, but it's REALLY bad Haskell: fToInt :: Float - Int fToInt f = if f = 10 then fToInt (f-10.0) else if (f = 9) then 9 else if (f = 8) then 8 else if (f = 7) then 7 else if (f = 6) then 6 else if (f = 5) then 5 else if (f = 4) then 4 else if (f = 3) then 3 else if (f = 2) then 2 else if (f =
Beginners Digest, Vol 17, Issue 10
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Re: Is Haskell for me? (Felipe Lessa) 2. Re: Re: Is Haskell for me? (geremy condra) 3. Re: Help for type matching (Hong Yang) 4. Re: Applicative Parsec (Heinrich Apfelmus) 5. maybe this could be improved? (Michael Mossey) 6. Installing packages in Ubuntu (Glurk) 7. Re: Installing packages in Ubuntu (Magnus Therning) 8. Re: Installing packages in Ubuntu (Tom Tobin) 9. MULTICONF-10 Call for papers (John Edward) -- Message: 1 Date: Fri, 6 Nov 2009 19:58:30 -0200 From: Felipe Lessa felipe.le...@gmail.com Subject: Re: [Haskell-beginners] Re: Is Haskell for me? To: Gaius Hammond ga...@gaius.org.uk Cc: beginners@haskell.org Message-ID: c2701f5c0911061358k5b84c06eoa49091140fe99...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On 11/6/09, Gaius Hammond ga...@gaius.org.uk wrote: To be fair, Python offloads its heavy lifting to C libraries - NumPy and SciPy run at very close to full C speed on large datasets. This is also how Matlab works. Unladen Swallow is an upcoming JIT compiler for Python. Where Haskell shines for computation is when you can leverage lazy evaluation. *If* you can offload most of your work to SciPy. Depending on what you do this is at least difficult. I don't know how much of a neural network can be represented as big fat matrix :). -- Felipe. -- Message: 2 Date: Fri, 6 Nov 2009 18:37:30 -0500 From: geremy condra debat...@gmail.com Subject: Re: [Haskell-beginners] Re: Is Haskell for me? To: Felipe Lessa felipe.le...@gmail.com Cc: beginners@haskell.org Message-ID: f3cc57c60911061537p27e7c23dib2e3534ff3b41...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 On Fri, Nov 6, 2009 at 4:58 PM, Felipe Lessa felipe.le...@gmail.com wrote: On 11/6/09, Gaius Hammond ga...@gaius.org.uk wrote: To be fair, Python offloads its heavy lifting to C libraries - NumPy and SciPy run at very close to full C speed on large datasets. This is also how Matlab works. Unladen Swallow is an upcoming JIT compiler for Python. Where Haskell shines for computation is when you can leverage lazy evaluation. *If* you can offload most of your work to SciPy. Depending on what you do this is at least difficult. I don't know how much of a neural network can be represented as big fat matrix :). -- Felipe. Neural networking can be easily handled in both Python and C. I've used my own Graphine graph theory package for it and found that it was quite easy and reasonably fast, and certainly LEDA is a very high performance, pretty easy-to-use library. There's no need to coerce ANNs into a matrix form if you don't want to. Geremy Condra -- Message: 3 Date: Fri, 6 Nov 2009 17:57:47 -0600 From: Hong Yang hyang...@gmail.com Subject: [Haskell-beginners] Re: Help for type matching To: beginners@haskell.org Message-ID: f31db34d0911061557n286d6938k1ac684d14f6c8...@mail.gmail.com Content-Type: text/plain; charset=utf-8 My mistake. I did not read the Text.CSV.ByteString document carefully. parseCSV requires a strict ByteString, but I was feeding a lazy one. Have a good weekend! Hong On Fri, Nov 6, 2009 at 3:47 PM, Hong Yang hyang...@gmail.com wrote: I have the following code: module Main where import System.Environment (getArgs) import Text.CSV.ByteString import qualified Data.ByteString.Lazy.Char8 as L main = do [args] - getArgs file - L.readFile args let result = parseCSV file case result of Nothing - putStrLn Error when parsing! Just contents - do putStrLn parsing OK! -- map_header_records contents which yielded the error as follows: Couldn't match expected type `Data.ByteString.Internal.ByteString' against inferred type `L.ByteString' In the first argument of `parseCSV', namely `file' In the expression: parseCSV file In the definition of `result': result = parseCSV file readFile in the Data.ByteString.Lazy.Char8 module returns ByteString type. Since the module is qualified as L, L.readFile returns L.ByteString. But parseCSV expects a ByteString. Sometimes this is annoying, because it makes type matching difficult (at least for me, a beginner). I really wish Haskell can intelligently treat L.ByteString,
Beginners Digest, Vol 17, Issue 11
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. parse String - Expression (John Moore) 2. Re: parse String - Expression (Felipe Lessa) 3. Re: parse String - Expression (Felipe Lessa) 4. Re: parse String - Expression (Daniel Fischer) 5. Re: Installing packages in Ubuntu (Nathan M. Holden) 6. Re: Installing packages in Ubuntu (Maur??cio CA) 7. Simple haskell problem ! Help please (Denis Firsov) 8. Re: Simple haskell problem ! Help please (Joe Fredette) 9. Re: Simple haskell problem ! Help please (Tim Attwood) -- Message: 1 Date: Sun, 8 Nov 2009 17:53:48 + From: John Moore john.moor...@gmail.com Subject: [Haskell-beginners] parse String - Expression To: beginners@haskell.org Message-ID: 4f7ad1ad0911080953t17ffd10co237995d6a6ce5...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 Hi, I'm trying to find a way to parseRPN (Reverse Polish Numbers) to expressions rather than to just numbers. e.g. I want the answer to be in the form (Multiply (Val 2) (Val 3)) rather than just the answer. Are these anyway near the steps parseRPN :: String-Expression This is a lot more complicated then I thought.!!! First do we have to read in a string is this (IsString) fromString :: String - a Then this goes on a stack pushStack :: a - Stack - Stack (Takes a value and puts in on a stack) Later we pop it off popStack :: Stack - (a,Stack) -- takes the value of the stack and leaves the stack Do we also have to define taking off the stack such as head(popstack) or fst(popstack) if we do we would probably have one for putting it onto a stack. Do we then turn the value into an Expression.? -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20091108/4fec4429/attachment-0001.html -- Message: 2 Date: Sun, 8 Nov 2009 16:49:37 -0200 From: Felipe Lessa felipe.le...@gmail.com Subject: Re: [Haskell-beginners] parse String - Expression To: beginners@haskell.org Message-ID: 20091108184937.ga22...@kira.casa Content-Type: text/plain; charset=us-ascii On Sun, Nov 08, 2009 at 05:53:48PM +, John Moore wrote: Hi, I'm trying to find a way to parseRPN (Reverse Polish Numbers) to expressions rather than to just numbers. e.g. I want the answer to be in the form (Multiply (Val 2) (Val 3)) rather than just the answer. You don't need to code all the parser by hand. You can use, for example, Parsec parsers. Spoilers ahead!!! If your data type is data Expr a = Multiply (Expr a) (Expr a) | Val a then you may write something like expression :: Parser a - Parser (Expr a) expression valParser = spaces (mult | val) where expr = expression valParser mult = char * (Multiply $ expr * expr) val = Val $ valParser using Parsec for a concrete example. HTH, -- Felipe. -- Message: 3 Date: Sun, 8 Nov 2009 16:53:00 -0200 From: Felipe Lessa felipe.le...@gmail.com Subject: Re: [Haskell-beginners] parse String - Expression To: beginners@haskell.org Message-ID: 20091108185300.gb22...@kira.casa Content-Type: text/plain; charset=us-ascii On Sun, Nov 08, 2009 at 04:49:37PM -0200, Felipe Lessa wrote: You don't need to code all the parser by hand. You can use, for example, Parsec parsers. IOW, you may use the language's implicit stack instead of building your own. -- Felipe. -- Message: 4 Date: Sun, 8 Nov 2009 20:00:10 +0100 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] parse String - Expression To: beginners@haskell.org Message-ID: 200911082000.11449.daniel.is.fisc...@web.de Content-Type: text/plain; charset=iso-8859-15 Am Sonntag 08 November 2009 18:53:48 schrieb John Moore: Hi, I'm trying to find a way to parseRPN (Reverse Polish Numbers) to expressions rather than to just numbers. e.g. I want the answer to be in the form (Multiply (Val 2) (Val 3)) rather than just the answer. I'd suggest using something like type Stack = [Expression] parseRPN :: Parser Expression parseRPN = rpn [] parseVal :: Parser Expression parseVal = do num - parseNumber return (Val num) rpn :: Stack - Parser Expression rpn stack = (do char '+' case stack of (x:y:ts) - rpn (Add x y:ts) _ - parsecFail BinOp requires two values on Stack) | (do char '*' case stack of (x:y:ts) - rpn
Beginners Digest, Vol 17, Issue 12
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Either Monadic Trouble (i?fai) 2. Re: Either Monadic Trouble (Henk-Jan van Tuyl) 3. Re: Either Monadic Trouble (Nicolas Pouillard) 4. Re: Either Monadic Trouble (Ertugrul Soeylemez) 5. Re: Re: Either Monadic Trouble (Nicolas Pouillard) 6. What is the best practice for code] (legajid) 7. turning a value into an expression (John Moore) 8. Re: turning a value into an expression (Deniz Dogan) 9. Re: Re: Either Monadic Trouble (i?fai) 10. Re: Re: Either Monadic Trouble (Nicolas Pouillard) -- Message: 1 Date: Mon, 09 Nov 2009 04:01:43 -0500 From: i?fai iae...@me.com Subject: [Haskell-beginners] Either Monadic Trouble To: Beginners@haskell.org Message-ID: 49f7c1fc-4b1f-4e7e-9585-fcaf5983e...@me.com Content-Type: text/plain; charset=windows-1252; format=flowed; delsp=yes With the below code, I am getting an error that I cannot resolve Chess.hs:52:82: Couldn't match expected type `Map [Char] [Char]' against inferred type `Either ParseError ConfigMap' In the third argument of `findWithDefault', namely `c' In the `documentRoot' field of a record In the first argument of `return', namely `Config {documentRoot = (findWithDefault web Document- Root c)}' The specific code is: getConf :: FilePath - IO (Either ParseError Config) getConf filePath = return $ do c - readConfig filePath -- (Either ParseError ConfigMap) return Config { documentRoot = Map.findWithDefault web Document-Root c } The type of c should be Either ParseError ConfigMap, which by my understanding of the Either monad would cause the c to be the Right side stripped, or skipped if Left. Full source for the module is below, and full project is hosted at http://patch-tag.com/r/iaefai/chess For some general information, I am replacing ConfigFile dependancy with a Parsec based config parser (I call it SimpleConfig) that suits my needs - it came from http://www.serpentine.com/blog/2007/01/31/parsing-a-simple-config-file-in-haskell/ originally and I modified it. On windows ConfigFile's dependancy on a posix regex library was causing trouble, so this is the effort to get rid of that dependancy. Any thoughts would be useful. There is one associated thought The original function used to get configuration back to the program is -- Mostly from Chris Done's Blog getConf :: FilePath - IO (Either (C.CPErrorData, String) Config) getConf filePath = runErrorT $ do let cp = C.emptyCP { optionxform = id } contents - liftIO $ readFile filePath config - C.readstring cp contents let get = C.get config DEFAULT Config $ get Document-Root I noted it used $ and in the code that I retrieved originally from Chris Done's blog (no longer able to find it) used * for additional items. I would like some easy method of constructing the new Config structure in my new code, especially if it can be done without the record syntax like this thing gets away with. I am not sure how this thing associated Document-Root with documentRoot mind you. Thank you again. iæfai. -- import Network.Shed.Httpd import Network.URI import Data.List.Split import Data.Either import Data.Map as Map import Text.ParserCombinators.Parsec import Control.Monad.Error import Control.Applicative import System.Directory import ChessBoard import SimpleConfig data Config = Config { documentRoot :: String } deriving (Read, Show) main :: IO () main = do let docPath = let config = Config { documentRoot = } putStrLn $ Using document root: ++ docPath putStrLn Starting up httpd on port server - initServer (request config) return () request :: Config - Request - IO Response request config req = do putStrLn $ Recieved ++ (show $ uriPath $ reqURI req) case url of ajax : _ - return $ Response 404 [] Not found. _ - do str - readFile ((documentRoot config) ++ uri) return $ Response 200 [] str where url = drop 1 $ splitOn / uri uri = uriPath $ reqURI req getConf :: FilePath - IO (Either ParseError Config) getConf filePath = return $ do c - readConfig filePath -- (Either ParseError ConfigMap) return Config { documentRoot = Map.findWithDefault web Document-Root c } -- ERROR
Beginners Digest, Vol 17, Issue 13
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: What is the best practice for code] (Brent Yorgey) 2. Re: turning a value into an expression (Brent Yorgey) 3. Re: Re: Either Monadic Trouble (Michael Snoyman) 4. Re: What is the best practice for code] (Chadda? Fouch?) 5. Double Trouble (Philip Scott) 6. Re: Double Trouble (Krzysztof Skrz?tnicki) 7. Re: Double Trouble (Philip Scott) 8. Re: Either Monadic Trouble (Daniel Fischer) 9. Complex list manipulation (legajid) -- Message: 1 Date: Mon, 9 Nov 2009 20:18:34 -0500 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] What is the best practice for code] To: beginners@haskell.org Message-ID: 20091110011834.ga3...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Mon, Nov 09, 2009 at 10:46:19PM +0100, legajid wrote: {-Second solution -} futiles2 xx = [(x, y, z) | x - xx, y - xx, z - xx, y x, z y] f2 = filter (\(x,y,z) - (x+y+z)==19) (futiles2 nombres ) {-Third solution -} f3 = filter (\(x,y,z) - (x+y+z)==19) ((\ xx - [(x, y, z) | x - xx, y - xx, z - xx, y x, z y]) nombres ) I think the second solution is best (the third solution seems hard to read). Shorter code is usually better, but avoid long lines that are hard to scan. Here's another possibility: f4 = filter (\(x,y,z) - x+y+z == 19) [(x,y,z) | x - [9,8..1], y - reverse [1..x-1], z - reverse [1..y-1]] This way you only generate (x,y,z) where x y z, and avoid all the wasted work of generating triples and then throwing them away. -Brent -- Message: 2 Date: Mon, 9 Nov 2009 20:21:12 -0500 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] turning a value into an expression To: beginners@haskell.org Message-ID: 20091110012112.gb3...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Mon, Nov 09, 2009 at 10:05:43PM +, John Moore wrote: Hi, How do I turn a value into an expression I want to do for e.g. 8 - 1 turn it into (subtract (Val8) (Val1) Any ideas Is this a homework problem? One good approach would be to make a data type Expr which represents expressions. It will have a constructor Val, a constructor Subtract, etc., one constructor for each operation you want to have in your expressions. Then make Expr an instance of the Num type class. -Brent -- Message: 3 Date: Tue, 10 Nov 2009 07:04:12 +0200 From: Michael Snoyman mich...@snoyman.com Subject: Re: [Haskell-beginners] Re: Either Monadic Trouble To: Nicolas Pouillard nicolas.pouill...@gmail.com Cc: Beginners beginners@haskell.org Message-ID: 29bf512f0911092104s3c58fe77qec186e50b1165...@mail.gmail.com Content-Type: text/plain; charset=utf-8 On Tue, Nov 10, 2009 at 1:12 AM, Nicolas Pouillard nicolas.pouill...@gmail.com wrote: Excerpts from iæfai's message of Tue Nov 10 00:05:04 +0100 2009: This is all very confusing. You say that it is defined in the transformers. Does this mean it is possible to use the code I am trying to get to work to do what I want? Yes by importing Control.Monad.Error You also mention the attempt package, I must admit that I am not entirely sure how to use it either. Note that I haven't done a lot of error handling in haskell (the extent usually involved Maybe) A new version should be released (on Haskell Cafe) pretty soon, some documentation links will be provided as well. If you find the documentation not clear enough then let me know. Update: attempt-0.0.1 *has* been released. Michael -- next part -- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20091109/365c7696/attachment-0001.html -- Message: 4 Date: Tue, 10 Nov 2009 10:16:48 +0100 From: Chadda? Fouch? chaddai.fou...@gmail.com Subject: Re: [Haskell-beginners] What is the best practice for code] To: legajid lega...@free.fr Cc: beginners@haskell.org Message-ID: e9350eaf0911100116y7ed6a8f3oa360b62d6b1b7...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Mon, Nov 9, 2009 at 10:46 PM, legajid lega...@free.fr wrote: {-   Third solution  -} f3 = filter (\(x,y,z) - (x+y+z)==19) ((\ xx - [(x, y, z) | x - xx, y - xx, z - xx, y x, z y]) nombres ) If you want to use list comprehension just use it for all filtering necessary : (Si tu veux utiliser les list comprehension
Beginners Digest, Vol 17, Issue 15
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Re: Why is type Integer - Integer and not (Num a) = a - a? (Chadda? Fouch?) 2. Re: Why is type Integer - Integer and not (Num a) = a - a? (Shawn Willden) 3. Re: Why is type Integer - Integer and not (Num a) = a - a? (Felipe Lessa) 4. Re: Why is type Integer - Integer and not (Num a) = a - a? (Nathan M. Holden) 5. Re: Why is type Integer - Integer and not (Num a) = a - a? (Chadda? Fouch?) 6. Re: maybe this could be improved? (Patrick LeBoutillier) 7. Re: maybe this could be improved? (Michael Mossey) 8. Re: maybe this could be improved? (Patrick LeBoutillier) -- Message: 1 Date: Thu, 12 Nov 2009 10:04:53 +0100 From: Chadda? Fouch? chaddai.fou...@gmail.com Subject: Re: [Haskell-beginners] Why is type Integer - Integer and not (Num a) = a - a? To: Dag Hovland dag.hovl...@uib.no Cc: beginners@haskell.org Message-ID: e9350eaf0911120104w47a61b3fiafa66ed762f13...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Thu, Nov 12, 2009 at 9:37 AM, Dag Hovland dag.hovl...@uib.no wrote: Hi! I have a problem with understanding some types given by ghc and hugs. The file loaded is: f1 = \x - x * 2 f2 x = x * 2 After they are loaded I get the following from ghci *Main :t f1 f1 :: Integer - Integer *Main :t f2 f2 :: (Num a) = a - a *Main :t \x - x * 2 \x - x * 2 :: (Num a) = a - a This is called the monomorphism restriction, it's a rule that state a binding _without_parameters_ shall be inferred of a monomorphic type unless an explicit signature is given. There are several reasons for it, some of efficiency (polymorphism has a cost) and some of a more technical nature, refer to the Haskell Report for a more detailed explanation. Some Haskellers think this restriction is no longer required, that GHC is now often intelligent enough to alleviate the cost of polymorphism, that the technical reasons are not really all that pertinent and that the default should be to infer the more general type in all case rather than confuse beginners and oblige experts to put explicit signatures. It is already possible to deactivate the restriction by using the -XNoMonomorphismRestriction argument (or putting the equivalent language pragma in the code itself or in the cabal description file) and making this the default is discussed for Haskell' (the future standard for Haskell). In the meantime, it is a good idea to put :set -XNoMonomorphismRestriction in your .ghci file since most usage of GHCi would only hit the disadvantages of this rule and reap no benefits from it. -- Jedaï -- Message: 2 Date: Thu, 12 Nov 2009 02:06:00 -0700 From: Shawn Willden shawn-hask...@willden.org Subject: Re: [Haskell-beginners] Why is type Integer - Integer and not (Num a) = a - a? To: beginners@haskell.org Message-ID: 200911120206.00364.shawn-hask...@willden.org Content-Type: text/plain; charset=iso-8859-1 On Thursday 12 November 2009 01:45:08 am Joe Fredette wrote: My guess is that, defining in GHCi let f x = x * 2 let g = \x - x * 2 the former doesn't default to anything (it just does inference) since it's a function definition, and the latter defaults the '2' to an Integer because it's a value -- or some suitable analog of that situation. Hmm. Would that also explain this? Prelude let f1 x = x * 2 Prelude :type f1 f1 :: (Num a) = a - a Prelude let f2 = \x - f1 x Prelude :type f2 f2 :: Integer - Integer Shawn. -- Message: 3 Date: Thu, 12 Nov 2009 08:40:49 -0200 From: Felipe Lessa felipe.le...@gmail.com Subject: Re: [Haskell-beginners] Why is type Integer - Integer and not (Num a) = a - a? To: Shawn Willden shawn-hask...@willden.org Cc: beginners@haskell.org Message-ID: c2701f5c0911120240le8bcb7ao85e7ade64e0d6...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Thu, Nov 12, 2009 at 7:06 AM, Shawn Willden shawn-hask...@willden.org wrote: Hmm.  Would that also explain this? Prelude let f1 x = x * 2 Prelude :type f1 f1 :: (Num a) = a - a Prelude let f2 = \x - f1 x Prelude :type f2 f2 :: Integer - Integer Yes, that's the same monomorphism restriction. Also, note that you are defaulting to Integer here: Prelude :s -Wall Prelude let f1 x = x * 2 Prelude :t f1 f1 :: (Num a) = a - a Prelude let f2 = \x - f1 x interactive:1:15:
Beginners Digest, Vol 17, Issue 17
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Question on data/type (Phillip Pirrip) 2. Re: Functor question. (Brent Yorgey) 3. Re: Question on data/type (i?fai) 4. Re: Question on data/type (Brent Yorgey) 5. Functor question (Matthew Wong) 6. Questions on data/type (Matthew Wong) 7. Re: Functor question (Jason Dusek) 8. Re: Questions on data/type (Jason Dusek) 9. Re: Question on data/type (David Virebayre) 10. Re: Question on data/type (Felipe Lessa) -- Message: 1 Date: Mon, 16 Nov 2009 00:33:51 -0500 From: Phillip Pirrip ppir...@gmail.com Subject: [Haskell-beginners] Question on data/type To: beginners@haskell.org Message-ID: 7dc11d2c-abde-4956-adcf-5a5c9ea24...@gmail.com Content-Type: text/plain; charset=us-ascii Hi, I have the following data defined. data TypeCon a = ValConA a | ValConB [a] | ValConC [[a]] So I can use functions with type like (a-a-a) - TypeCon a - TypeCon a - TypeCon a for all 3 value types, and I think is easier to define one single typeclass for (+), (*) etc. If I want to express the following idea (the following won't compiler): data TypeCon a = ValConA a | ValConB [ValConA a] | ValConC [ValConB a] Is this even a good idea? If so how could I proceed? The closest thing I can get to compiler is like this: data TypeCon a = ValConA a | ValConB [TypeCon a] Which is a nightmare when I try to manipulate anything in this structure. The alternative I guess is to use 3 different type constructors, data TypeConA a = ValConA a data TypeConB a = ValConB [ValConA a] data TypeConC a = ValConC [ValConB a] but then I can't use one signal typeclass for (+) etc. Am I correct? thx, //pip -- Message: 2 Date: Mon, 16 Nov 2009 06:47:43 -0500 From: Brent Yorgey byor...@seas.upenn.edu Subject: Re: [Haskell-beginners] Functor question. To: beginners@haskell.org Message-ID: 20091116114743.ga7...@seas.upenn.edu Content-Type: text/plain; charset=us-ascii On Sun, Nov 15, 2009 at 08:07:36PM -0800, Alexander Dunlap wrote: In general, people recommend against using constriants on datatypes, recommending instead to put those constraints on the functions that operate on the datatypes. I'm not quite sure why that is, though. It is because adding a constraint to a datatype definition only puts a constraint on the *constructor*---in particular, you don't get any constraints when pattern-matching, and you have to put the constraints on functions that operate on the datatype anyway. -Brent -- Message: 3 Date: Mon, 16 Nov 2009 11:57:45 -0500 From: i?fai iae...@me.com Subject: Re: [Haskell-beginners] Question on data/type To: Phillip Pirrip ppir...@gmail.com Cc: Beginners@haskell.org Message-ID: 074ddf16-e80a-4f22-8c36-bb2527af0...@me.com Content-Type: text/plain; charset=iso-8859-1 I will try to help with my limited knowledge and what I believe to be going on. When you try to compile: data TypeCon a = ValConA a | ValConB [ValConA a] | ValConC [ValConB a] You get this: Not in scope: type constructor or class `ValConA' Not in scope: type constructor or class `ValConB' What you have here is a type constructor TypeCon and a data constructor ValConA, ValConB, ValConC. When you are constructing your different data constructors (such as ValConA) you have to give it type constructors, or substitutes like a. You can do this: data TypeCon a = ValConA a | ValConB [TypeCon a] Regards, iæfai. On 2009-11-16, at 12:33 AM, Phillip Pirrip wrote: Hi, I have the following data defined. data TypeCon a = ValConA a | ValConB [a] | ValConC [[a]] So I can use functions with type like (a-a-a) - TypeCon a - TypeCon a - TypeCon a for all 3 value types, and I think is easier to define one single typeclass for (+), (*) etc. If I want to express the following idea (the following won't compiler): data TypeCon a = ValConA a | ValConB [ValConA a] | ValConC [ValConB a] Is this even a good idea? If so how could I proceed? The closest thing I can get to compiler is like this: data TypeCon a = ValConA a | ValConB [TypeCon a] Which is a nightmare when I try to manipulate anything in this structure. The alternative I guess is to use 3 different type constructors, data TypeConA a = ValConA a data TypeConB a = ValConB [ValConA a] data TypeConC a = ValConC [ValConB a] but then I can't use one signal typeclass for (+) etc. Am I correct? thx,
Beginners Digest, Vol 17, Issue 18
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. Named fields in data types (legajid) 2. Re: Named fields in data types (Chadda? Fouch?) 3. Re: Question on data/type (Phillip Pirrip) 4. Re: Question on data/type (Daniel Fischer) 5. Re: Named fields in data types (legajid) 6. Re: Named fields in data types (Edward Z. Yang) 7. Windows API and FFI (i?fai) 8. Re: Windows API and FFI (Jeff Zaroyko) -- Message: 1 Date: Tue, 17 Nov 2009 22:24:26 +0100 From: legajid lega...@free.fr Subject: [Haskell-beginners] Named fields in data types To: beginners@haskell.org Message-ID: 4b03148a.10...@free.fr Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hello, i've some trouble with named fields in data types. data Carnet = Adresse { nom :: String, cp :: Integer, ville :: String } | Telephone {nom::String, telnum::String} deriving Show contact01 = Adresse Didier 51100 Reims contact02 = Adresse {nom=Laure, cp=0} -- line 1 --contact02 Adresse { ville=Nogent } -- line 2 --contact02 { ville=Nogent } -- line 3 contact03=Telephone Didier 0326... -- line 4 When loading this source : line 1 says warning : Fields not initialized :ville line 2 and 3 when uncommented give parse error (possibly indentation) I'm ok with line 1. Is it possible to write such things as line2 or 3 ? Which syntax ? Thanks for help. Didier. -- Message: 2 Date: Tue, 17 Nov 2009 22:55:05 +0100 From: Chadda? Fouch? chaddai.fou...@gmail.com Subject: Re: [Haskell-beginners] Named fields in data types To: legajid lega...@free.fr Cc: beginners@haskell.org Message-ID: e9350eaf0911171355o5dc7f19y5f19563bca298...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 On Tue, Nov 17, 2009 at 10:24 PM, legajid lega...@free.fr wrote: Hello, i've some trouble with named fields in data types. data Carnet = Adresse  { nom :: String, cp :: Integer, ville :: String  }    |    Telephone {nom::String, telnum::String}  deriving Show contact01 = Adresse Didier 51100 Reims contact02 = Adresse {nom=Laure, cp=0} -- line 1 --contact02 Adresse { ville=Nogent }    -- line 2 --contact02 { ville=Nogent }           -- line 3 contact03=Telephone Didier 0326...    -- line 4 When loading this source : line 1 says warning : Fields not initialized :ville line 2 and 3 when uncommented give parse error (possibly indentation) I'm ok with line 1. Is it possible to write such things as line2 or 3 ? Which syntax ? line 2 appears correct except you forgot the =... Of course some fields aren't initialized so you may have a problem if you try to access them later on. (La ligne 2 est correcte sauf que tu as oublié le égal =... Bien sûr certains des champs ne sont pas initialisés et ça pourrait poser problème si tu essaies d'y accéder plus tard) Note that you can also create a new value with some fields in common with an old value, for instance : (Note que tu peux aussi créer une nouvelle valeur partageant un certain nombre de champs avec une autre valeur déjà déclarée) contact01 = Adresse Didier 51100 Reims contact02 = contact01 { nom = Charles } Which leads to the practice of using records to create a default setting value where you just modify the field that concern you. (Ce qui a donné lieu à l'idiome qui consiste à utiliser un type enregistrement (avec des champs nommés) pour les configuration avec une valeur réglage par défaut dont on ne modifie que les champs qui nous intéresse) main = xmonad defaultConfig {terminal = konsole} -- Jedaï -- Message: 3 Date: Tue, 17 Nov 2009 21:46:45 -0500 From: Phillip Pirrip ppir...@gmail.com Subject: Re: [Haskell-beginners] Question on data/type To: beginners@haskell.org Message-ID: de32292c-b1fb-4bc4-a0c5-42a5d16d7...@gmail.com Content-Type: text/plain; charset=us-ascii Hi, Thanks everyone for their patience on my question and took the time to write back. I was thinking to re-phrase my question (to correct some typo etc), but many of you have already guessed my intent. I am trying to write a simple Matrix library, as my little learning exercise, so TypeConA : Scalar TypeConB : 1D array TypeConC : 2D array /matrix. So I would like to have one typeclass for operations like Scalar +/* Matrix etc. Felipe: you are way ahead of me (like showing me the answer before I do my
Beginners Digest, Vol 17, Issue 19
Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than Re: Contents of Beginners digest... Today's Topics: 1. points-free problem (I. J. Kennedy) 2. Re: points-free problem (Daniel Fischer) 3. Re: points-free problem (Michael Mossey) 4. Re: points-free problem (Daniel Fischer) 5. Re: Re: Is Haskell for me? (Jon Harrop) 6. Re: Re: Is Haskell for me? (Ben Lippmeier) 7. Re: Re: Is Haskell for me? (Nicolas Pouillard) 8. Re: Re: Is Haskell for me? (Ben Lippmeier) 9. Re: Re: Is Haskell for me? (Nicolas Pouillard) -- Message: 1 Date: Fri, 20 Nov 2009 16:22:08 -0600 From: I. J. Kennedy j...@realmode.com Subject: [Haskell-beginners] points-free problem To: beginners@haskell.org Message-ID: 1008bfc90911201422t56f00c6ep429f929d155d7...@mail.gmail.com Content-Type: text/plain; charset=UTF-8 I know I'm going to kick myself when the answer is revealed by one of you kind folks, but after staring at this a while I just can't figure out what's going on. The compiler (ghci) is trying so hard to tell me what's wrong, but I am failing to understand. I thought for the most part one could take a function definition like f x = (blah blah blah) x and turn it into points-free style by f = (blah blah blah) But from the dialog below, my assumption is incorrect. Help? I. J. Kennedy sortBy (compare `on` fst) [(2,3),(0,1),(1,5)]  -- test a little sort expression [(0,1),(1,5),(2,3)] let sortpairs xss = sortBy (compare `on` fst) xss  -- make it into a function :t sortpairs sortpairs :: (Ord a) = [(a, b)] - [(a, b)] sortpairs [(2,3),(0,1),(1,5)] [(0,1),(1,5),(2,3)] let sortpairs = sortBy (compare `on` fst)   -- points-free style sortpairs [(2,3),(0,1),(1,5)] interactive:1:24:    No instance for (Num ())     arising from the literal `1' at interactive:1:24    Possible fix: add an instance declaration for (Num ())    In the expression: 1    In the expression: (1, 5)    In the first argument of `sortpairs', namely      `[(2, 3), (0, 1), (1, 5)]' :t sortpairs sortpairs :: [((), b)] - [((), b)] -- what?! -- Message: 2 Date: Fri, 20 Nov 2009 23:41:53 +0100 From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-beginners] points-free problem To: beginners@haskell.org Message-ID: 200911202341.53566.daniel.is.fisc...@web.de Content-Type: text/plain; charset=utf-8 Am Freitag 20 November 2009 23:22:08 schrieb I. J. Kennedy: I know I'm going to kick myself when the answer is revealed by one of you kind folks, but after staring at this a while I just can't figure out what's going on. The compiler (ghci) is trying so hard to tell me what's wrong, but I am failing to understand. I thought for the most part one could take a function definition like f x = (blah blah blah) x and turn it into points-free style by f = (blah blah blah) But from the dialog below, my assumption is incorrect. Help? I. J. Kennedy Monomorphism restriction. By that, if you bind f via f = (blah blah blah) and don't give a type signature, f gets a monomorphic type. Dreadful details in the report, section 4.5.(?) Put :set -XNoMonomorphismRestriction in your .ghci file. sortBy (compare `on` fst) [(2,3),(0,1),(1,5)]  -- test a little sort expression [(0,1),(1,5),(2,3)] let sortpairs xss = sortBy (compare `on` fst) xss  -- make it into a function :t sortpairs sortpairs :: (Ord a) = [(a, b)] - [(a, b)] sortpairs [(2,3),(0,1),(1,5)] [(0,1),(1,5),(2,3)] let sortpairs = sortBy (compare `on` fst)   -- points-free style sortpairs [(2,3),(0,1),(1,5)] interactive:1:24:    No instance for (Num ())     arising from the literal `1' at interactive:1:24    Possible fix: add an instance declaration for (Num ())    In the expression: 1    In the expression: (1, 5)    In the first argument of `sortpairs', namely      `[(2, 3), (0, 1), (1, 5)]' :t sortpairs sortpairs :: [((), b)] - [((), b)] -- what?! -- Message: 3 Date: Fri, 20 Nov 2009 15:10:48 -0800 From: Michael Mossey m...@alumni.caltech.edu Subject: Re: [Haskell-beginners] points-free problem To: beginners beginners@haskell.org Message-ID: 4b0721f8.4090...@alumni.caltech.edu Content-Type: text/plain; charset=UTF-8; format=flowed I've been on this list for something like 7 months and I think monomorphism restriction is the answer to about 70% of newbie/intermediate questions. I don't