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

Dan Doel dan.doel at gmail.com
Fri Apr 26 03:49:20 CEST 2013


I can't think of any at the moment that are still in force. However, one
that might have been relevant at the time is:

    data C a => Foo a = Foo a a

    foo :: Foo a -> (a, a)
    foo ~(Foo x y) = (x, y)

Irrefutable matches used to be disallowed for GADT-like things, which would
break the above if it were translated to GADTs. Now they just don't
introduce their constraints.

However, another thing to consider is that getting rid of data type
contexts was accepted into the language standard. It's not really possible
to fix them by translation to GADTs in the report, because GADTs aren't in
the report, and probably won't be for some time, if ever. And putting a
fixed version natively into the report would require nailing down a lot of
details. For instance, are the contexts simply invalid on newtypes, or do
they just work the old way?

I don't really think they're worth saving in general, though. I haven't
missed them, at least.

-- Dan


On Thu, Apr 25, 2013 at 3:19 PM, Gábor Lehel <illissius at gmail.com> wrote:

> Good point, again. Is that the only problem with it?
>
>
> On Thu, Apr 25, 2013 at 5:57 PM, Dan Doel <dan.doel at gmail.com> wrote:
>
>> It is not completely backwards compatible, because (for instance) the
>> declaration:
>>
>>     newtype C a => Foo a = Foo a
>>
>> was allowed, but:
>>
>>     newtype Foo a where
>>       Foo :: C a => a -> Foo a
>>
>> is an illegal definition. It can only be translated to a non-newtype data
>> declaration, which changes the semantics.
>>
>>
>> On Thu, Apr 25, 2013 at 10:35 AM, Gábor Lehel <illissius at gmail.com>wrote:
>>
>>> I've wondered this too. What would have been wrong with a simple
>>> source-to-source translation, where a constraint on the datatype itself
>>> translates to the same constraint on each of its constructors? Perhaps it
>>> would be unintuitive that you would have to pattern match before gaining
>>> access to the constraint? On a superficial examination it would have been
>>> backwards-compatible, allowing strictly more programs than the previous
>>> handling.
>>>
>>> On Thu, Apr 25, 2013 at 12:38 PM, harry <voldermort at hotmail.com> wrote:
>>>
>>>> If I understand correctly, the problem with datatype contexts is that
>>>> if we
>>>> have e.g.
>>>>   data Eq a => Foo a = Foo a
>>>> the constraint Eq a is thrown away after a Foo is constructed, and any
>>>> method using Foos must repeat Eq a in its type signature.
>>>>
>>>> Why were these contexts removed from the language, instead of "fixing"
>>>> them?
>>>>
>>>> PS This is following up on a discussion on haskell-beginners, "How to
>>>> avoid
>>>> repeating a type restriction from a data constructor". I'm interested in
>>>> knowing whether there's a good reason not to allow this, or if it's
>>>> just a
>>>> consequence of the way type classes are implemented by compilers.
>>>>
>>>>
>>>> _______________________________________________
>>>> Haskell-Cafe mailing list
>>>> Haskell-Cafe at haskell.org
>>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>>
>>>
>>>
>>>
>>> --
>>> Your ship was destroyed in a monadic eruption.
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe at haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>>
>>
>
>
> --
> Your ship was destroyed in a monadic eruption.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130425/1236bc76/attachment-0001.htm>


More information about the Haskell-Cafe mailing list