[Haskell] Contexts on Data Declarations
Iavor Diatchki
iavor.diatchki at gmail.com
Sat Aug 5 17:52:53 EDT 2006
Hello,
I was just looking at the details of how contexts on datatypes work in
Haskell'98
and I noticed the following. The report states that the context on a
particular constructor should contain all those predicates that
mention only variables that are in the fields of the constructor.
This wording does not scale very well to mult-paramater type classes,
and indeed Hugs (20050308) and GHC (6.4.1) do different things. Here
is an example:
> class C a b
>
> data C a b => T a b = Mk a
According to Hugs, Mk :: a -> T a b, which follows the report: the
constarint is not added because it mentions a variable, b, which is
not in the fields of Mk.
According to GHC, however, Mk :: C a b => a -> T a b, which also makes
sense if we interpret the report to mean: "all those predicates that
constrain a variable in the fields of the constructor".
I know that contexts on data types are not a very popular part of the
Haskell design, but it would be nice to be consistent. To me it seems
that GHC's interpretation is the correct one.
-Iavor
PS: Appologies if this is fixed in later versions of Hugs, I don't
have a newer version at the moment to try it out.
More information about the Haskell
mailing list