[Haskell-beginners] Bind parser returning wrong return type

Rohit Sharma rohits79 at gmail.com
Mon Nov 17 05:27:11 UTC 2014


Thanks much Kim, that was very helpful.

On Sat, 15 Nov, 2014 11:09 pm Kim-Ee Yeoh <ky3 at atamo.com> wrote:

> 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
>  _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20141117/17391f8c/attachment.html>


More information about the Beginners mailing list