[Haskell-beginners] Problem with GADTs and Parsec
Brandon Allbery
allbery.b at gmail.com
Sat Feb 8 19:21:36 UTC 2014
On Sat, Feb 8, 2014 at 2:10 PM, Lorenzo Tabacchini <lortabac at gmx.com> wrote:
> If I do:
>
> exprParser :: Parsec String u (Expr a)
> exprParser = parens exprParser
> <|> (reserved "true" >> return (Bool True))
> <|> (reserved "false" >> return (Bool False))
> <|> (stringLiteral >>= return . Text)
>
> The compiler says: "Couldn't match type `Bool' with `[Char]'"
> Where am I wrong?
>
The type of exprParser doesn't do what you intend. Specifically, the `a` in
`(Expr a)` is chosen by the *caller* and you have to deal with that choice
somehow --- it does not mean you can pick a different `a` in different
parts of your code.
There are several ways you might redesign your types, but I think I'll have
to let someone else address those.
--
brandon s allbery kf8nh sine nomine associates
allbery.b at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140208/fa9a2c21/attachment.html>
More information about the Beginners
mailing list