[Haskell-beginners] Bind parser returning wrong return type

Kim-Ee Yeoh ky3 at atamo.com
Sat Nov 15 15:08:49 UTC 2014


Your questions aren't lame. They are common confusions from those who come
from a not-so-mathy background.

Your first question:

    Shouldn't the return type be of (Char, [Char])?

suggests that you're confusing the type synonym of (Parser a), which is
String -> (a, String), with just the right-hand-side, (a, String).

Your "z" expression has type Parser ([Char], Char), which means the same
thing as String -> ((String, Char), String).

How did that happen?

Because

    item `bind` (\x -> (\y -> result (x,y))) "Rohit"

is equivalent to

    item `bind` ( (\x -> (\y -> result (x,y))) "Rohit" )

as those last two expressions go together by the parsing rules.

So what you actually have is

    item `bind` (\y -> result ("Rohit",y))

The first argument to bind has type Parser Char, the second argument (a ->
Parser (String,a)).

The result is exactly what's expected: Parser (String, Char), i.e. String
-> ((String, Char), String).

p.s. This might be what you're looking for: Try evaluating

   item "Rohit"

in the repl.


-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20141115/27946e74/attachment.html>


More information about the Beginners mailing list