Changes between Version 25 and Version 26 of DefaultSuperclassInstances


Ignore:
Timestamp:
May 28, 2013 9:53:39 AM (2 years ago)
Author:
simonpj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DefaultSuperclassInstances

    v25 v26  
    8888=== Default superclass instances ===
    8989
    90 First, we allow a class declaration to include a '''default superclass instance declaration''' for some, none, or all of its superclass constraints. We say that superclasses with default implementations are '''intrinsic''' superclasses. Example:
     90First, we allow a class declaration to include a '''default superclass instance declaration''' for some, none, or all of its superclass constraints (transitively). We say that superclasses (transitively) with default implementations are '''intrinsic''' superclasses. Example:
    9191{{{
    9292    class Functor f => Applicative f where
     
    110110}}}
    111111Here, `Applicative` is an intrinsic superclass of `Monad`.
     112
     113We might also want to give a different implementation of `fmap` for monads than the
     114one generated by the `Applicative` class declaration:
     115{{{
     116    class Applicative f => Monad f where
     117      (>>=) :: f a -> (a -> f b) -> f b
     118      instance Applicative f where
     119        hiding instance Functor
     120        ff <*> fs = ff >>= \ f -> fs >>= \ s -> return (f s)
     121      instance Functor f where
     122        fmap f x = x >>= \y -> return (f y)
     123}}}
     124(In fact this `fmap` would, after optimisation of a particular instance and if enough inlining too place, generate the same code, but that might not always be the case.)
    112125
    113126=== Instance declarations ===