
Simon Peyton-Jones wrote:
3. Dictionaries are packaged in data constructors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A very useful new feature is this. When a data type is declared in in GADT syntax, the context of the constructor is *required* when constructing *available* when matching
For example data T a where T1 :: Num a => a -> T a T2 :: Bounded a => T a
f :: T a -> a f (T1 x) = x+1 f T2 = maxBound
Notice that f is not overloaded. The Num needed in the first branch is satisfied by the T1 pattern match; and similarly for the T2 pattern match.
This feature has been often requested, becuase it allows you to package a dictionary into an ordinary (non-existential) data type, and be able to use it.
NOTE: the Haskell 98 syntax for data type declarations data Num a => T a = T1 a behaves exactly as specified in H98, and *not* in the new way. The Num dictionary is *required* when constructing, and *required* when matching I think this is stupid, but it's what H98 says. To get the new behaviour, use GADT-style syntax, even though the data type being defined is does not use the GADT-ness.
We may want to propose to change that for Haskell'. What do you think? Manuel