type Parser a = String → [(a,String)]item :: Parser Charitem = λinp → case inp of[] → [](x:xs) → [(x,xs)]failure :: Parser afailure = λinp → []return :: a → Parser areturn v = λinp → [(v,inp)](+++) :: Parser a → Parser a → Parser ap +++ q = λinp → case p inp of[] → q inp[(v,out)] → [(v,out)]parse :: Parser a → String → [(a,String)]parse p inp = p inpp :: Parser (Char,Char)p = do x ← itemitemy ← itemreturn (x,y)It is described in pages 189-216 in [1].I assume the bind operator (==>) was overwritten by(>>=) :: Parser a → (a → Parser b) → Parser b p>>= f = λinp → case parse p inp of[ ] → [ ][ (v, out) ] → parse (f v) outin order to manipulate the do expr to make the p function work, right?2017-11-05 21:56 GMT+01:00 Tobias Brandt <to_br@uni-bremen.de>:______________________________Hey,
can you show us your Parser definition?
Cheers,
Tobias
----- Nachricht von Marcus Manning <iconsize@gmail.com> ---------
Datum: Sun, 5 Nov 2017 18:51:57 +0100
Von: Marcus Manning <iconsize@gmail.com>
Antwort an: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org>
Betreff: [Haskell-beginners] Could not get parser ready
An: beginners@haskell.org______________________________Hello,
I follow the instructions of script [1] in order to set up a parser functionality. But I' get into problems at page 202 with the code:
p :: Parser (Char,Char)
p = do
x ← item
item
y ← item
return (x,y)
ghci and ghc throw errors:
Prelude> let p:: Parser (Char,Char); p = do {x <- item; item; y <- item; return (x,y)}
<interactive>:10:65: error:
• Couldn't match type ‘[(Char, String)]’ with ‘Char’
Expected type: String -> [((Char, Char), String)]
Actual type: Parser ([(Char, String)], [(Char, String)])
• In a stmt of a 'do' block: return (x, y)
In the expression:
do x <- item
item
y <- item
return (x, y)
In an equation for ‘p’:
p = do x <- item
item
y <- item
....
Did the semantics of do expr changed?
[1] https://userpages.uni-koblenz.de/~laemmel/paradigms1011/reso urces/pdf/haskell.pdf
Cheers,
iconfly._________________
Beginners mailing list
Beginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman /listinfo/beginners
----- Ende der Nachricht von Marcus Manning <iconsize@gmail.com> -----
_________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners