
Hi All, I am a newbie to Haskell, and have been using Programming in Haskell along with Eric Meijer videos covering the book syllabus. I am currently on Chapter 8 Functional Parsers, and trying to implement few of the examples given in the book. Following is the example : item = \inp -> case inp of [] -> [] (x:xs) -> [(x,xs)] p = do x <- item y <- item z <- item return (x,y,z) ========= When I compile it using GHCI, I get the following error : [1 of 1] Compiling Main ( parser.hs, interpreted ) parser.hs:5:8: No instance for (Monad ((->) [t])) arising from a do statement at parser.hs:5:8-16 Possible fix: add an instance declaration for (Monad ((->) [t])) In a stmt of a 'do' expression: x <- item In the expression: do x <- item y <- item z <- item return (x, y, z) In the definition of `p': p = do x <- item y <- item z <- item .... Failed, modules loaded: none. ========= I tried googling for samples, above error message etc. But not getting to solution. Can anyone guide me as to what am I doing wrong and how can I fix this. Regards, Amiruddin Nagri, India GTalk : amir.nagri@gmail.com

Amiruddin Nagri
Hi All,
I am a newbie to Haskell, and have been using Programming in Haskell along with Eric Meijer videos covering the book syllabus. I am currently on Chapter 8 Functional Parsers, and trying to implement few of the examples given in the book.
Following is the example :
item = \inp -> case inp of [] -> [] (x:xs) -> [(x,xs)]
p = do x <- item y <- item z <- item return (x,y,z)
=========
When I compile it using GHCI, I get the following error :
[1 of 1] Compiling Main ( parser.hs, interpreted )
parser.hs:5:8: No instance for (Monad ((->) [t])) arising from a do statement at parser.hs:5:8-16
Try importing Control.Monad.Instances and see if that gets it to work.
Possible fix: add an instance declaration for (Monad ((->) [t])) In a stmt of a 'do' expression: x <- item In the expression: do x <- item y <- item z <- item return (x, y, z) In the definition of `p': p = do x <- item y <- item z <- item .... Failed, modules loaded: none.
=========
I tried googling for samples, above error message etc. But not getting to solution. Can anyone guide me as to what am I doing wrong and how can I fix this.
Regards, Amiruddin Nagri, India
GTalk : amir.nagri@gmail.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

Hi The code in this chapter isn't actually Haskell - some details are elided to make the presentation clearer. To run the code you want to get the file mentioned in the closing remarks of the chapter (page 85, section 8.9). http://www.cs.nott.ac.uk/~gmh/book.html http://www.cs.nott.ac.uk/~gmh/parser.lhs Best wishes Stephen

On 23 May 2010 08:41, Stephen Tetley
The code in this chapter isn't actually Haskell - some details are elided to make the presentation clearer.
There is also the paper - Monadic Parsing in Haskell - which presents the parsers as legal Haskell98: http://www.cs.nott.ac.uk/~gmh/pearl.pdf

I am getting following error while trying to load
http://www.cs.nott.ac.uk/~gmh/parser.lhs
Prelude> :l parsers2.hs
parsers2.hs:1:7:
Could not find module `Parsing':
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
Am I missing something again ?
Thanks for help,
Amiruddin Nagri,
Bangalore, 560008, KA
India
Y! IM : amir_nagri@yahoo.com
GTalk : amir.nagri@gmail.com
On Sun, May 23, 2010 at 1:11 PM, Stephen Tetley
Hi
The code in this chapter isn't actually Haskell - some details are elided to make the presentation clearer. To run the code you want to get the file mentioned in the closing remarks of the chapter (page 85, section 8.9).
http://www.cs.nott.ac.uk/~gmh/book.htmlhttp://www.cs.nott.ac.uk/%7Egmh/book.html
http://www.cs.nott.ac.uk/~gmh/parser.lhshttp://www.cs.nott.ac.uk/%7Egmh/parser.lhs
Best wishes
Stephen

Hi - it looks like I pointed you to the wrong file: You want to download both these two and put them in the same directory - http://www.cs.nott.ac.uk/~gmh/Parsing.lhs http://www.cs.nott.ac.uk/~gmh/parser.lhs Parsing.lhs is the library, parser.lhs is the example module that has an expression parser. Sorry for the confusion. Best wishes Stephen
participants (3)
-
Amiruddin Nagri
-
Ivan Lazar Miljenovic
-
Stephen Tetley