Changes between Version 27 and Version 28 of DefaultSuperclassInstances


Ignore:
Timestamp:
May 28, 2013 10:14:30 AM (14 months ago)
Author:
simonpj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DefaultSuperclassInstances

    v27 v28  
    6060=== Design goal 2: write implementations of sub-classes that imply their superclass implementations === 
    6161 
    62 Example 1: once you say 
     62 * Example 1: once you say 
    6363{{{ 
    6464instance Ord (T a) where 
    6565  compare = ... 
    6666}}} 
    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) 
    6868{{{ 
    6969class Eq a => Ord a where 
     
    7373}}} 
    7474 
    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`. 
    7878 
    7979Obvious 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 opt-out mechanism" below).