[Haskell-beginners] Bind parser returning wrong return type
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?
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 ->
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
in the repl.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners