<div dir="ltr">type Parser a = String → [(a,String)]<div><br></div><div>item :: Parser Char </div><div>item = λinp → case inp of </div><div> [] → [] </div><div> (x:xs) → [(x,xs)]</div><div>failure :: Parser a </div><div>failure = λinp → []</div><div><br></div><div>return :: a → Parser a </div><div>return v = λinp → [(v,inp)]</div><div><br></div><div>(+++) :: Parser a → Parser a → Parser a </div><div>p +++ q = λinp → case p inp of </div><div> [] → q inp </div><div> [(v,out)] → [(v,out)]</div><div><br></div><div>parse :: Parser a → String → [(a,String)]</div><div>parse p inp = p inp</div><div><br></div><div>p :: Parser (Char,Char)</div><div>p = do
x ← item </div><div> item </div><div> y ← item </div><div> return (x,y)</div><div><div><br></div><div>It is described in pages 189-216 in [1].</div><div><br></div><div>[1] <a href="https://userpages.uni-koblenz.de/~laemmel/paradigms1011/resources/pdf/haskell.pdf">https://userpages.uni-koblenz.de/~laemmel/paradigms1011/resources/pdf/haskell.pdf</a></div></div><div><br></div><div>I assume the bind operator (==>) was overwritten by</div><div><br></div><div>(>>=) :: Parser a → (a → Parser b) → Parser b
p </div><div>>>= f = λinp → case parse p inp of </div><div> [ ] → [ ] </div><div> [ (v, out) ] → parse (f v) out<br></div><div><br></div><div>in order to manipulate the do expr to make the p function work, right?</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-11-05 21:56 GMT+01:00 Tobias Brandt <span dir="ltr"><<a href="mailto:to_br@uni-bremen.de" target="_blank">to_br@uni-bremen.de</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div style="font-family:Arial;font-size:14px">
<p>Hey,<br>
<br>
can you show us your Parser definition? <br>
<br>
Cheers,<br>
Tobias <br>
<br>
----- Nachricht von Marcus Manning <<a href="mailto:iconsize@gmail.com" target="_blank">iconsize@gmail.com</a>> ---------<br>
Datum: Sun, 5 Nov 2017 18:51:57 +0100<br>
Von: Marcus Manning <<a href="mailto:iconsize@gmail.com" target="_blank">iconsize@gmail.com</a>><br>
Antwort an: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <<a href="mailto:beginners@haskell.org" target="_blank">beginners@haskell.org</a>><br>
Betreff: [Haskell-beginners] Could not get parser ready<br>
An: <a href="mailto:beginners@haskell.org" target="_blank">beginners@haskell.org</a></p>
<blockquote style="border-left:2px solid blue;margin-left:2px;padding-left:12px" type="cite">
<p></p><div><div class="h5">Hello,<br>
<br>
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:<br>
<br>
p :: Parser (Char,Char)<br>
p = do<br>
x ← item<br>
item<br>
y ← item<br>
return (x,y)<br>
<br>
<br>
ghci and ghc throw errors:<br>
Prelude> let p:: Parser (Char,Char); p = do {x <- item; item; y <- item; return (x,y)}<br>
<br>
<interactive>:10:65: error:<br>
• Couldn't match type ‘[(Char, String)]’ with ‘Char’<br>
Expected type: String -> [((Char, Char), String)]<br>
Actual type: Parser ([(Char, String)], [(Char, String)])<br>
• In a stmt of a 'do' block: return (x, y)<br>
In the expression:<br>
do x <- item<br>
item<br>
y <- item<br>
return (x, y)<br>
In an equation for ‘p’:<br>
p = do x <- item<br>
item<br>
y <- item<br>
....<br>
Did the semantics of do expr changed?<br>
<br>
[1] <a href="https://userpages.uni-koblenz.de/~laemmel/paradigms1011/resources/pdf/haskell.pdf" target="_blank">https://userpages.uni-koblenz.<wbr>de/~laemmel/paradigms1011/<wbr>resources/pdf/haskell.pdf</a><br>
<br>
Cheers,<br>
<br>
iconfly.<br></div></div>
______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell" target="_blank">Beginners@haskell</a>.<a>orghttp://<wbr>mail.haskell.org/cgi-bin/<wbr>mailman/listinfo/beginners</a><p></p>
</blockquote>
<p><br>
<br>
<br>
----- Ende der Nachricht von Marcus Manning <<a href="mailto:iconsize@gmail.com" target="_blank">iconsize@gmail.com</a>> -----<br>
<br></p>
</div>
<br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>