... | ... | @@ -52,17 +52,17 @@ Significant changes planned for the 7.4 branch are: |
|
|
class Coll c where
|
|
|
type X a :: Constraint
|
|
|
insert :: X a => a -> c a -> c a
|
|
|
isntance Coll [] where
|
|
|
instance Coll [] where
|
|
|
type X a = Eq a
|
|
|
insert x [] = [x]
|
|
|
insert x (y:ys) | x==y = ys
|
|
|
| otherwise = y : insert x ys
|
|
|
```
|
|
|
|
|
|
Here `X` is an assocaited constraints synonmy of the class `Coll`. The key point is that differnet instances can give different definitions to `X`. The GHC wiki page describese the design [ http://hackage.haskell.org/trac/ghc/wiki/KindFact WikiConstraint](http://hackage.haskell.org/trac/ghc/wiki/KindFact WikiConstraint), and Max's blog posts give more examples [ http://blog.omega-prime.co.uk/?p=61 ConstraintFamlies\], \[http://blog.omega-prime.co.uk/?p=127 ConstraintKind](http://blog.omega-prime.co.uk/?p=61 ConstraintFamlies], [http://blog.omega-prime.co.uk/?p=127 ConstraintKind).
|
|
|
Here `X` is an associated constraint synonym of the class `Coll`. The key point is that differnet instances can give different definitions to `X`. The GHC wiki page describes the design [ http://hackage.haskell.org/trac/ghc/wiki/KindFact WikiConstraint](http://hackage.haskell.org/trac/ghc/wiki/KindFact WikiConstraint), and Max's blog posts give more examples [ http://blog.omega-prime.co.uk/?p=61 ConstraintFamlies\], \[http://blog.omega-prime.co.uk/?p=127 ConstraintKind](http://blog.omega-prime.co.uk/?p=61 ConstraintFamlies], [http://blog.omega-prime.co.uk/?p=127 ConstraintKind).
|
|
|
|
|
|
- **Associated type synonym defaults.** Haskell lets you give a *default method* for the operations of a class.
|
|
|
Associated type synonym defaults let you declare a *default type instance* for the associated type synonyums of a class. This feature, implemented by Max Bolingbroke, nicely fills out missing design corner. For example
|
|
|
Associated type synonym defaults let you declare a *default type instance* for the associated type synonyms of a class. This feature, implemented by Max Bolingbroke, nicely fills out missing design corner. For example
|
|
|
|
|
|
```wiki
|
|
|
class C a where
|
... | ... | |