Changes between Version 27 and Version 28 of DefaultSuperclassInstances
 Timestamp:
 May 28, 2013 10:14:30 AM (3 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

DefaultSuperclassInstances
v27 v28 60 60 === Design goal 2: write implementations of subclasses that imply their superclass implementations === 61 61 62 Example 1: once you say62 * Example 1: once you say 63 63 {{{ 64 64 instance Ord (T a) where 65 65 compare = ... 66 66 }}} 67 then the implementation of `(==)` in `Eq` is obvious. So, in the class decl for `Ord` we'd like to say (modulo syntax, see below)67 then the implementation of `(==)` in `Eq` is obvious. So, in the class decl for `Ord` we'd like to say (modulo syntax, see below) 68 68 {{{ 69 69 class Eq a => Ord a where … … 73 73 }}} 74 74 75 Example 2: once you say `instance Monad M`, the instances for `Functor M` and `Applicative M` can be derivived from the definitions of `(>>=)` and `return`. And similarly if you say `instance Applicative M`, the `Functor M` instance is derivable.76 77 Example 3: once you say `instance Traversable T` you can derive `Foldable` and `Functor`.75 * Example 2: once you say `instance Monad M`, the instances for `Functor M` and `Applicative M` can be derivived from the definitions of `(>>=)` and `return`. And similarly if you say `instance Applicative M`, the `Functor M` instance is derivable. 76 77 * Example 3: once you say `instance Traversable T` you can derive `Foldable` and `Functor`. 78 78 79 79 Obvious question: if something is both `Foldable` and `Applicative`, which `Functor` instance do you get? Answer: the programmer must be able to control this (see "the optout mechanism" below).