about parser question < Programming in haskell _ chapter 8 >

well,i am reading the book :<Programming in haskell > chapter 8 functional parsers this chapter try teaching an parser technology,but i have some problem about do keyword --some brief info of types : type Parser a = String -> [(a,String)] item :: Parser Char --item "abc" = [('a',"bc")] return' :: a -> Parser a --return' 'a' "foo" = [('a',"foo")] --below code complier notice... sorry format p2 :: Parser (Char,Char) p2 = do x <- item item y <- item return' (x,y) "No instance for (Monad ((-)) String)) arising from a execute statement Possible fix : add an instance declaration for (Monad ((-)) String)) In a stmt of a 'do' expression : y <- item In the expression: do { x <- item; item; y <- item; return' (x,y)} In an equation for 'p2': p2 = do { x <- item; item; y <- item; ....}" thanks for any help jiangzhen mail:jiangzhen3s@qq.com

I think you can check full source code at its web site to see what you
missed.
My thought: did you make Parser as a instance of Monad?
-Haisheng
On Mon, Jul 18, 2011 at 5:20 PM, anyzhen
well,i am reading the book :<*Programming in haskell *> *chapter 8* *functional parsers * this chapter try teaching an parser technology,but i have some problem about *do* keyword
--some brief info of types : type Parser a = String -> [(a,String)] item :: Parser Char --item "abc" = [('a',"bc")] return' :: a -> Parser a --return' 'a' "foo" = [('a',"foo")]
--below code complier notice... sorry format p2 :: Parser (Char,Char) p2 = do x <- item item y <- item return' (x,y) *"No instance for (Monad ((-)) String)) * * arising from a execute statement ** ** ** ** ** * * Possible fix : add an instance declaration for **(Monad ((-)) String))** * *In a stmt of a 'do' expression : y <- item** ** ** ** ** * *In the expression:** ** ** ** ** ** ** ** * * do {** x <- item;** ** ** ** ** ** ** ** * * item;** ** ** ** ** ** ** ** ** ** * * y <- item;** ** ** ** ** ** ** ** * * return' (x,y)}** ** ** ** ** ** ** * * In an equation for 'p2':** ** ** ** ** ** ** ** * * p2 ** ** ** ** ** ** ** ** ** * * = do { ** x <- item;** ** ** ** ** ** ** * * item;** ** ** ** ** ** ** ** * * y <- item;** ** ** ** ** ** ** * * ....**}"** ** ** ** ** ** ** ** * * * *thanks for any help * *jiangzhen mail:jiangzhen3s@qq.com*
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Note that the presentation of functional parsers in the book
simplifies things a little, particularly the book avoids mentioning
newtypes explicitly though they are implicit in the section 8.9
Chapter Remarks.
The code on Graham Hutton's website uses newtypes and is is directly runnable:
http://www.cs.nott.ac.uk/~gmh/book.html#code
On 18 July 2011 12:17, Haisheng Wu
I think you can check full source code at its web site to see what you missed. My thought: did you make Parser as a instance of Monad? -Haisheng
participants (3)
-
anyzhen
-
Haisheng Wu
-
Stephen Tetley