[Haskell-cafe] Why were datatype contexts removed instead of "fixing them"?

wren ng thornton wren at freegeek.org
Fri Apr 26 04:31:36 CEST 2013


On 4/25/13 9:49 PM, Dan Doel wrote:
> I don't really think they're worth saving in general, though. I haven't
> missed them, at least.

The thing I've missed them for (and what I believe they were originally
designed for) is adding constraints to derived instances. That is, if I
have:

    data Bar a => Foo a = ... deriving Baz

Then this is equivalent to:

    data Foo a = ...
    instance Bar a => Baz (Foo a) where ...

where the second ellipsis is filled in by the compiler. Now that these
constraints have been removed from the language, I've had to either (a)
allow instances of derived classes which do not enforce sanity
constraints, or (b) implement the instances by hand even though they're
entirely boilerplate.

The behavior of these constraints is certainly unintuitive for beginners,
but the constraints themselves are very helpful when programming with
phantom types and type-level functions for constraints.

-- 
Live well,
~wren




More information about the Haskell-Cafe mailing list