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

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

2013-04-26 04:31, wren ng thornton skrev:
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.
I think standalone deriving solves this: deriving instance Bar a => Baz (Foo a) / Emil
participants (2)
-
Emil Axelsson
-
wren ng thornton