[Haskell-cafe] Simple GADT parser for the eval example

Greg Buchholz haskell at sleepingsquirrel.org
Wed Nov 1 14:01:07 EST 2006

Ulf Norell wrote:
> I'm not sure what you're asking...

    Me neither probably.
> , but it's possible to get
>   my_read :: .. => Expr -> Term a
> Previously given code:
> >-- Give a GADT for representation types
> >data R a where
> >  Rint :: R Int
> >  Rbool :: R Bool
> >  Rpair :: R a -> R b -> R (a,b)

    Yeah, I especially liked Joost Visser's version which is pretty
slick.  I was just wondering if it was possible to accomplish the same
task in a different way, using type classes instead of GADTs, which
would seem to work in a more top-downish fashion, as opposed to
bottom-upish.  But I'm not an expert enough with type systems to know if

Ambiguous type variable `b' in the constraint:
      `MyRead b'                                  
        arising from use of `my_read' at gadt_wobbly.hs:65:28-36
    Probable fix: add a type signature that fixes these type variable(s)

...problem was fixable by adding a type signature or grafting on some
additional type machinery.


Greg Buchholz

More information about the Haskell-Cafe mailing list