Re: [Haskell-cafe] beginner question: assigning local variable to a function
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On May 7, 2009, at 14:03 , Magnus Therning wrote: adam vogt wrote: This is most likely attributable to the use of different compilers. I don't see how accepting such a variant can cause ambiguity, but I'm not quite sure whether it is legal H98. Just a bit curious then what compiler Brandon was using. I'm using GHC 6.10.2 on AMD64 Linux (Arch). Actually it's probably because, rather than track separate rules depending on whether I'm embedded in other layout (read: "do"), I just remember to use the stricter rules everywhere. (This affects both "let" and "if".) - -- 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 -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.10 (Darwin) iEYEARECAAYFAkoDSFUACgkQIn7hlCsL25VV+QCglo4Q1fCHl4coiRuT4tn0GXtb qqAAoI5BsygYL39i6UuWTYS+tRtXK8bQ =zn3F -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] beginner question: assigning local variable to a function
adam vogt wrote: This is most likely attributable to the use of different compilers. I don't see how accepting such a variant can cause ambiguity, but I'm not quite sure whether it is legal H98. Just a bit curious then what compiler Brandon was using. I'm using GHC 6.10.2 on AMD64 Linux (Arch). /M On 5/6/09, Magnus Therning wrote: Brandon S. Allbery KF8NH wrote: On May 6, 2009, at 12:18 , Nico Rolle wrote: why does this don't work? test = let a = (>) in 1 `a` 2 Works fine here once I correct your indentation (the "in" needs to be indented at least as far as the "l" in "let"). Really? For me it's enough to have "in" indented more then "test", and one space is enough: test = let a = (>) in 1 `a` 2 /M -- Magnus Therning(OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Magnus Therning(OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe signature.asc Description: OpenPGP digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] beginner question: assigning local variable to a function
This is most likely attributable to the use of different compilers. I don't see how accepting such a variant can cause ambiguity, but I'm not quite sure whether it is legal H98. On 5/6/09, Magnus Therning wrote: > Brandon S. Allbery KF8NH wrote: > > On May 6, 2009, at 12:18 , Nico Rolle wrote: > > > > > why does this don't work? > > > > > > test = let a = (>) > > > in 1 `a` 2 > > > > > > > > > Works fine here once I correct your indentation (the "in" needs to be > indented at least as far as the "l" in "let"). > > > > Really? For me it's enough to have "in" indented more then "test", and one > space is enough: > > test = let a = (>) > in 1 `a` 2 > > /M > > -- > Magnus Therning(OpenPGP: 0xAB4DFBA4) > magnus@therning.org Jabber: magnus@therning.org > http://therning.org/magnus identi.ca|twitter: magthe > > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] beginner question: assigning local variable to a function
Brandon S. Allbery KF8NH wrote: On May 6, 2009, at 12:18 , Nico Rolle wrote: why does this don't work? test = let a = (>) in 1 `a` 2 Works fine here once I correct your indentation (the "in" needs to be indented at least as far as the "l" in "let"). Really? For me it's enough to have "in" indented more then "test", and one space is enough: test = let a = (>) in 1 `a` 2 /M -- Magnus Therning(OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe signature.asc Description: OpenPGP digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] beginner question: assigning local variable to a function
Oh sorry guys was rlly a stupid indentation mistake next time i'll post the error message too thanks regards 2009/5/6 Brandon S. Allbery KF8NH : > On May 6, 2009, at 12:18 , Nico Rolle wrote: >> >> why does this don't work? >> >> test = let a = (>) >> in 1 `a` 2 > > > Works fine here once I correct your indentation (the "in" needs to be > indented at least as far as the "l" in "let"). > > -- > 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 university KF8NH > > > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] beginner question: assigning local variable to a function
On May 6, 2009, at 12:18 , Nico Rolle wrote: why does this don't work? test = let a = (>) in 1 `a` 2 Works fine here once I correct your indentation (the "in" needs to be indented at least as far as the "l" in "let"). -- 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 PGP.sig Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] beginner question: assigning local variable to a function
hi why does this don't work? test = let a = (>) in 1 `a` 2 regards ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Beginner question
>>> module Main(main) where >>> main = putStr (show []) > > What type is your "[]" here? > (...) > You may think it's irrelevant, since empty lists are showed the same; but > they are not: for example, ([] :: [Char]) would be shown as '""' (empty > string). Of course you're right. Didn't know how to type an empty list. "main = putStr (show ([] :: [Char]))" seems so obvious now. Thanks, Benjamin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Beginner question
On 2 Jan 2009, at 19:57, Benjamin Bach wrote: Supposing I have the following code: module Main(main) where main = putStr (show []) What type is your "[]" here? main :: IO () putStr :: String -> IO () show [] :: String show :: Show a => a -> String Now, how is Hugs or GHCi supposed to know the type of "[]"? The only information it has is that it's type belongs to the class "Show". You may think it's irrelevant, since empty lists are showed the same; but they are not: for example, ([] :: [Char]) would be shown as '""' (empty string). I will get these errors from GHC and Hugs respectively: Main.hs:2:16: Ambiguous type variable `a' in the constraint: `Show a' arising from a use of `show' at Main.hs:2:16-22 Probable fix: add a type signature that fixes these type variable(s) ERROR "src/Main.hs":2 - Unresolved top-level overloading *** Binding : main *** Outstanding context : Show b But if I change my code to the following, it will compile. module Main(main) where main = putStr (show [1]) I have no problems typing in "putStr (show [])" in Hugs... runs fine. So what's wrong? I've really tried hard to think of an explanation, but with no luck.. Thanks, Benjamin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Beginner question
> "Benjamin" == Benjamin Bach writes: Benjamin> Supposing I have the following code: >> module Main(main) where main = putStr (show []) Benjamin> I will get these errors from GHC and Hugs respectively: >> Main.hs:2:16: Ambiguous type variable `a' in the constraint: >> `Show a' arising from a use of `show' at Main.hs:2:16-22 >> Probable fix: add a type signature that fixes these type >> variable(s) >> ERROR "src/Main.hs":2 - Unresolved top-level overloading *** >> Binding : main *** Outstanding context : Show b Benjamin> But if I change my code to the following, it will Benjamin> compile. >> module Main(main) where main = putStr (show [1]) Benjamin> I have no problems typing in "putStr (show [])" in Benjamin> Hugs... runs fine. So what's wrong? I've really tried Benjamin> hard to think of an explanation, but with no luck.. I would say that it is complaining that it doesn't know what type of empty list you want it to show. of course, they will all display the same at run time, but it's compile time that is the problem. -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Beginner question
Supposing I have the following code: > module Main(main) where > main = putStr (show []) I will get these errors from GHC and Hugs respectively: > Main.hs:2:16: > Ambiguous type variable `a' in the constraint: > `Show a' arising from a use of `show' at Main.hs:2:16-22 > Probable fix: add a type signature that fixes these type variable(s) > ERROR "src/Main.hs":2 - Unresolved top-level overloading > *** Binding : main > *** Outstanding context : Show b But if I change my code to the following, it will compile. > module Main(main) where > main = putStr (show [1]) I have no problems typing in "putStr (show [])" in Hugs... runs fine. So what's wrong? I've really tried hard to think of an explanation, but with no luck.. Thanks, Benjamin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] beginner question re example in Hutton's "Programming in Haskell"y
On Fri, Feb 23, 2007 at 11:18:46PM -0500, David Cabana wrote: > I have been trying to work through Graham Hutton's "Programming in > Haskell", but have hit something of a snag in chapter 8.4. Hutton > presents some sample code which I am trying to run, with no luck so > far. Here is the code as I constructed it by gathering snippets > presented across three pages. > > module Main where > > -- as per Hutton page 75 > type Parser a = String -> [(a, String)] > > -- page 75 > return :: a -> Parser a > return v = \inp -> [(v,inp)] This return conflicts with the one in Prelude, and (while similar) they are not interchangable. > -- page 76 > failure :: Parser a > failure = \inp -> [ ] This is analogous to Prelude.fail. Fortunately Hutton didn't call it that :) > item :: Parser Char > item = \inp -> case inp of > [ ] -> [ ] > (x:xs)-> [(x,xs)] Looks reasonable > parse :: Parser a -> String -> [(a,String)] > parse p inp = p inp Same here > -- page 77 > p :: Parser (Char, Char) > p = do x <- item > item > y <- item > return (x,y) > Bad! Due to the Layout Rule that is parsed as a single long statement... I'm quite suprised you didn't get a parse error. It needs to be: p :: Parser (Char, Char) p = do x <- item item y <- item return (x,y) But, this still won't work. essentially the 'do' uses Prelude.return, Prelude.(>>), and Prelude.(>>=), which work on defined Monads; but your parser type is not properly declared as a monad. (and cannot be, because it is a type synonym.) You could define: (>>) :: Parser x -> Parser y -> Parser y (p1 >> p2) l = [ (s,rs2) | (f,rs1) <- p1 l , (s,rs2) <- p2 rs1 ] (>>=) :: Parser x -> (x -> Parser y) -> Parser y (p1 >>= fn) l = [ (s,rs2) | (f,rs1) <- p1 l , (s,rs2) <- fn f rs1 ] then use those (do-notation ignores scope so it must be desugared): p :: Parser (Char, Char) p = item Main.>>= \x -> item Main.>> item Main.>>= \y -> Main.return (x,y) This should work. Famous last words I know :) > When I tried to load this code, I got this error message: > > Ambiguous occurrence `return' > It could refer to either `return', defined at /Users/joe/haskell/ > parse2.hs:8:0 > or `return', imported from Prelude > > OK. My reasoning was that Hutton took the trouble to define return, > so I decided to use the local definition instead of the one in the > Prelude. I changed the last line from "return (x,y)" to "Main.return > (x,y)". The new error message is worse: > > Couldn't match expected type `Char' > against inferred type `[(Char, String)]' > In the expression: x > In the first argument of `return', namely `(x, y)' > In the expression: return (x, y) > > Hutton provided explicit type signatures, so I did not expect type > issues. > > I decided to take another approach. The book has a website that lists > errata and provides code listings. The code for chapter eight is at > http://www.cs.nott.ac.uk/~gmh/Parsing.lhs > > When I read Hutton's code, I noticed that he begins by importing > Monad. The code I list above is from chapter 8, pages 75-77 of the > book. Monads have not yet been mentioned. The book's index shows that > monads aren't mentioned till page 113, in chapter 10. I also notice > that in his code, Hutton makes repeated use of a symbol P whose > meaning I do not know. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] beginner question re example in Hutton's "Programming in Haskell"
I have been trying to work through Graham Hutton's "Programming in Haskell", but have hit something of a snag in chapter 8.4. Hutton presents some sample code which I am trying to run, with no luck so far. Here is the code as I constructed it by gathering snippets presented across three pages. module Main where -- as per Hutton page 75 type Parser a = String -> [(a, String)] -- page 75 return :: a -> Parser a return v = \inp -> [(v,inp)] -- page 76 failure :: Parser a failure = \inp -> [ ] item :: Parser Char item = \inp -> case inp of [ ] -> [ ] (x:xs)-> [(x,xs)] parse :: Parser a -> String -> [(a,String)] parse p inp = p inp -- page 77 p :: Parser (Char, Char) p = do x <- item item y <- item return (x,y) When I tried to load this code, I got this error message: Ambiguous occurrence `return' It could refer to either `return', defined at /Users/joe/haskell/ parse2.hs:8:0 or `return', imported from Prelude OK. My reasoning was that Hutton took the trouble to define return, so I decided to use the local definition instead of the one in the Prelude. I changed the last line from "return (x,y)" to "Main.return (x,y)". The new error message is worse: Couldn't match expected type `Char' against inferred type `[(Char, String)]' In the expression: x In the first argument of `return', namely `(x, y)' In the expression: return (x, y) Hutton provided explicit type signatures, so I did not expect type issues. I decided to take another approach. The book has a website that lists errata and provides code listings. The code for chapter eight is at http://www.cs.nott.ac.uk/~gmh/Parsing.lhs When I read Hutton's code, I noticed that he begins by importing Monad. The code I list above is from chapter 8, pages 75-77 of the book. Monads have not yet been mentioned. The book's index shows that monads aren't mentioned till page 113, in chapter 10. I also notice that in his code, Hutton makes repeated use of a symbol P whose meaning I do not know. What do I have to do to make this code work? I know I can use Hutton's code from the website, but I expected the code presented in the book to work, or the code on the website to restrict itself to what has been discussed in the book. Am I missing something here? Thanks, David Cabana ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Beginner Question
On 2/9/07, vishy anand <[EMAIL PROTECTED]> wrote: I have just started on my journey in learning Haskell.I have started off reading wikibook,then will read yet another tutorial on haskell.Please guide me if I am on right track The book I used on my learning was "Haskell: the craft of functional programming". I liked it, although some parts of it seems to be for people who are learning to program for the first time. All in all I thought it did a nice job teaching me. If the price is a concern you may be able to find it in a library or you could probably buy an used book at low prices, since the new ones costs about $50. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Beginner Question
Hi Vishy, You wrote: I have just started on my journey in learning Haskell. Welcome aboard! We all wish you an enjoyable and (type)safe trip. I have started off reading wikibook, then will read yet another tutorial on haskell. Please guide me if I am on right track Those are both great tutorials. What past experience do you have in functional programming, and programming in general? Regards, Yitz ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Beginner Question
I have just started on my journey in learning Haskell.I have started off reading wikibook,then will read yet another tutorial on haskell.Please guide me if I am on right track thks ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] beginner question - file handling
Hi do x <- readFile "test.txt" print (length (lines x)) That prints out the number of lines in a file, but once you have done lines x, you can do anything you want to the lines Thanks Neil On 3/5/06, Richard Gooding <[EMAIL PROTECTED]> wrote: > Hi, > > can someone please point me at some code to read in the lines for a file - a > working example ? > > I've have checked the tutorials on the wiki (some broken links) but couldn't > find anything. - and my "The craft of functiional programming" doesn't have > an example either ! > > thanks > Rich > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] beginner question - file handling
Hi, can someone please point me at some code to read in the lines for a file - a working example ? I've have checked the tutorials on the wiki (some broken links) but couldn't find anything. - and my "The craft of functiional programming" doesn't have an example either ! thanks Rich ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe