Changes between Version 7 and Version 8 of DefaultSuperclassInstances


Ignore:
Timestamp:
Mar 10, 2011 5:52:09 PM (4 years ago)
Author:
simonpj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DefaultSuperclassInstances

    v7 v8  
    99('''SLPJ''' I don't understand this distinction clearly.) This proposal concerns the latter phenomenon, which is currently such a nuisance that Functor and Applicative are not superclasses of Monad. Nobody wants to be forced to write Functor and Applicative instances, just to access the Monad interface. Moreover, any proposal to refine the library by splitting a type class into depth-layers is (rightly!) greeted with howls of protest as an absence of superclass instances gives rise to breakage of the existing codebase.
    1010
     11== The proposal ==
     12
    1113Concretely, the proposal is to
    1214
    13   * 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  * 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
    1416{{{
    1517    class Functor f => Applicative f where
     
    2628        ff <*> fs = ff >>= \ f -> fs >>= \ s -> return (f s)
    2729}}}
    28 but no to
     30  but "no" to
    2931{{{
    3032    class (Tweedle dum, Tweedle dee) => Rum dum dee where
     
    3234      instance Tweedle dee where ...
    3335}}}
    34   * let subclass instance declarations spawn intrinsic superclass instances by default -- if we have
     36
     37  * Let subclass instance declarations spawn intrinsic superclass instances by default -- if we have
    3538{{{
    3639    class Bar t[x] => Foo x where
     
    3942    instance C => Foo s where ...
    4043}}}
    41 we automatically acquire a default superclass instance
     44  we automatically acquire a default superclass instance
    4245{{{
    4346    instance C => Bar t[s] where ...
    4447}}}
    45   * let subclass instance declarations provide and override the methods of their intrinsic superclasses with no extra delimitation; so we may write
     48
     49  * Let subclass instance declarations provide and override the methods of their intrinsic superclasses with no extra delimitation; so we may write
    4650{{{
    4751    instance Monad Blah where
     
    4953      ba >>= bf = ...
    5054}}}
    51 and acquire the Monad instance, along with fully formed Applicative and Functor instances. By requiring that intrinsic superclasses be class-distinct, we ensure that the distribution of methods to spawned instances is unambiguous. Moreover, local overrides beat the default. If we write
     55  and acquire the Monad instance, along with fully formed Applicative and Functor instances. By requiring that intrinsic superclasses be class-distinct, we ensure that the distribution of methods to spawned instances is unambiguous. Moreover, local overrides beat the default. If we write
    5256{{{
    5357    instance Monad Blah where
     
    5660      bs >> bt = ...
    5761}}}
    58 we override the default (>>) but keep the (<*>) in the spawned Applicative instance.
    59   * to inhibit default-spawning with the syntax
     62  we override the default (>>) but keep the (<*>) in the spawned Applicative instance.
     63
     64  * To inhibit default-spawning with the syntax
    6065{{{
    6166    instance Sub x where
     
    6368      hiding instance Super
    6469}}}
    65 which acts to prevent the generation of instances for Super and all of Super's intrinsic superclasses in turn. We need this, so that we can write
     70  which acts to prevent the generation of instances for Super and all of Super's intrinsic superclasses in turn. We need this, so that we can write
    6671{{{
    6772    instance Monad Blah where
     
    7378      traverse f bx = ...  -- inducing a default implementation of Functor
    7479}}}
    75 or indeed to turn off all the defaults and provide a standalone Functor instance.
     80  or indeed to turn off all the defaults and provide a standalone Functor instance.
    7681
    77   * while we're about it, to allow multi-headed instance declarations for class-disjoint conjunctions, with the same semantics for constraint duplication and method distribution as for the defaults, so
     82  * While we're about it, to allow multi-headed instance declarations for class-disjoint conjunctions, with the same semantics for constraint duplication and method distribution as for the defaults, so
    7883{{{
    7984    instance S => (C x, C' x) where
     
    8186      methodOfC' = ...
    8287}}}
    83 is short for
     88  is short for
    8489{{{
    8590    instance S => C x where
     
    8893      methodOfC' = ...
    8994}}}
     95
    9096This proposal fits handily with the [wiki:KindFact kind Fact proposal], which allows multiple constraints to be abbreviated by ordinary type synonyms.
    9197