[Haskell] Type Class Question

Paul Govereau govereau at eecs.harvard.edu
Mon Nov 21 19:20:41 EST 2005


Hello,

I was hoping that someone could answer a question I have about the
type class system. In Haskell, I cannot write a term with an exact
constraint:

> data X = X
> bar :: Show X => X -> String
> bar x = show x

According to the Haskell 98 report, a qualifier can only be applied to
type variables, but I don't see where the trouble is. The term seems
to have reasonable type, and I don't see any reason why the
dictionary-passing translation shouldn't work out; I am wondering what
problems you run into if this restriction is lifted?

Note, with GHC and Glasgow extensions you can write this program:

> data Y a = Y
> foo :: Show (Y a) => Y a -> String
> foo x = show x

However, the first program is still ruled out. Are there any
type-class experts out there that can offer an explanation?

Thanks,
Paul


More information about the Haskell mailing list