Changes between Version 8 and Version 9 of DefaultSuperclassInstances


Ignore:
Timestamp:
Mar 10, 2011 6:06:53 PM (4 years ago)
Author:
simonpj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DefaultSuperclassInstances

    v8 v9  
    1111== The proposal ==
    1212
    13 Concretely, the proposal is to
     13Concretely, the proposal is as follows.
    1414
    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
     15First, 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:
    1616{{{
    1717    class Functor f => Applicative f where
    1818      return :: x -> f x
    1919      (<*>) :: f (s -> t) -> f s -> f t
     20
    2021      (>>) :: f s -> f t -> f t
    2122      fs >> ft = return (flip const) <*> fs <*> ft
     23
    2224      instance Functor f where
    2325        fmap = (<*>) . return
     26}}}
     27Note 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!
    2428
     29Here is another example:
     30{{{
    2531    class Applicative f => Monad f where
    2632      (>>=) :: f a -> (a -> f b) -> f b
     
    2834        ff <*> fs = ff >>= \ f -> fs >>= \ s -> return (f s)
    2935}}}
    30   but "no" to
     36Here,  and `Applicative` is an intrinsic superclass of `Monad`.
     37
     38Each default superclass instance declaration in a `class` declaration must be for
     39a distinct class.  So one of these is OK and the other is not:
    3140{{{
     41    -- This is ILLEGAL
    3242    class (Tweedle dum, Tweedle dee) => Rum dum dee where
    3343      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
    3448      instance Tweedle dee where ...
    3549}}}