Changes between Version 8 and Version 9 of DefaultSuperclassInstances
 Timestamp:
 Mar 10, 2011 6:06:53 PM (3 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

DefaultSuperclassInstances
v8 v9 11 11 == The proposal == 12 12 13 Concretely, the proposal is to13 Concretely, the proposal is as follows. 14 14 15 * Allow class declarations to include '''default superclass instance delcaration''' for some, none, or all of their given superclass constraints, provided all such instances have distinct classes. We say that superclasses with default implementations are '''intrinsic''' superclasses. "Yes" to 15 First, we allow a class declaration to include a '''default superclass instance delcaration''' for some, none, or all of its superclass constraints. We say that superclasses with default implementations are '''intrinsic''' superclasses. Example: 16 16 {{{ 17 17 class Functor f => Applicative f where 18 18 return :: x > f x 19 19 (<*>) :: f (s > t) > f s > f t 20 20 21 (>>) :: f s > f t > f t 21 22 fs >> ft = return (flip const) <*> fs <*> ft 23 22 24 instance Functor f where 23 25 fmap = (<*>) . return 26 }}} 27 Note the `instance` declaration nested inside the `class` declaration. This is the default superclass instance declaration, and `Functor` thereby becomes an intrisic superclass of `Applicative`. Moreover, note that the definition of `fmap` uses the `<*>` operation of `Applicative`; that is the whole point! 24 28 29 Here is another example: 30 {{{ 25 31 class Applicative f => Monad f where 26 32 (>>=) :: f a > (a > f b) > f b … … 28 34 ff <*> fs = ff >>= \ f > fs >>= \ s > return (f s) 29 35 }}} 30 but "no" to 36 Here, and `Applicative` is an intrinsic superclass of `Monad`. 37 38 Each default superclass instance declaration in a `class` declaration must be for 39 a distinct class. So one of these is OK and the other is not: 31 40 {{{ 41  This is ILLEGAL 32 42 class (Tweedle dum, Tweedle dee) => Rum dum dee where 33 43 instance Tweedle dum where ... 44 instance Tweedle dee where ... 45 46  But this is OK 47 class (Tweedle dum, Tweedle dee) => Rum dum dee where 34 48 instance Tweedle dee where ... 35 49 }}}