We already have a notation for the "fixed" version:
data Foo a where Foo :: Eq a => a -> Foo a
Moreover, this is arguably the "right" notation because you can vary the context per-constructor:
data Bar a where Bar1 :: Eq a => a -> Bar a Bar2 :: (Ix a, Show a) => a -> a -> Bar a
You may want to make suggesitons to the Haskell Prime group, but I'm disinclined to add yet new behaviour to GHC when an existing solution does the job.
This only works when pattern matching on the constructor, and GADTs are no different to classical data types for this. Functions which uses a Foo without pattern matching will require a redundant type context in either case.
@gidyn: What would the type of x be in your example?
You probably want x to introduce the validity of constraint Eq a. So the type would be somewhat dual to Eq a => Pair a -> a: using it would prove the constraint Eq a, rather than requiring evidence for the constraint. Something like Pair a -> (Eq a; a).
It seems to me this change would complicate the type system a lot, while the benefits are rather doubtful.
@gidyn: You probably meant x :: Eq a => Pair a -> a.
Consider isaacdupree's equal (undefined :: Pair (() -> ())). Surely this should be legal: undefined inhabits every type. Yet attempting to evaluate it leads to using == from Eq (() -> ()) which does not exist.
Consider isaacdupree's equal (undefined :: Pair (() -> ())). Surely this should be legal: undefined inhabits every type. Yet attempting to evaluate it leads to using == from Eq (() -> ()) which does not exist.
The use of DatatypeContexts would make this equivalent to equal (undefined :: Eq ? => Pair (() -> ())), so the type he's asking about couldn't (and shouldn't) be constructed when using this extension.
Excluding some nefarious uses of undefined seems like a reasonable price to pay for turning on a useful extension.
As far as I understand, the proposal is not sound.
I think that there is some misunderstanding here. This is not proposing to change the actual type system, just that the DatatypeContexts extension should enable automatic context inference. This is a more limited form of SPJ's (...) => proposal, but tied to the extension which most requires it, and without the syntactic noise.
I like the idea of fixing this too. The main Idea would be to hide Contexts from sight. As an example of how this could be useful consider Num were a newtype instead of a type class
newtype (Num n) => Num' n = Num' ntype Int' = Num' Int(+) :: Num' n -> Num' n -> Num' n
and even if you enable ugly extensions like UndecidableInstances this can not fix your problems if you want to use type families or functional dependencies.
you can not make an instance
class SomeClass a b | a -> binstance (Num n) => SomeClass n b
without immediately blocking all other possible Instances.
Maybe these DatatypeContexts based containers are a bit less flexible than common classes in that they don't mix, but if you know they don't have to mix it makes instances a lot easier and safer.
of course you can always add the context explicitly but it would be nice if ghc infer them. As gidyn said I don't think this would change the type system overly much. You would just get contexts that don't need not be explicitly stated. Every time you do context checks you can easily derive them from the type.