Changes between Version 7 and Version 8 of DefaultSuperclassInstances
 Timestamp:
 Mar 10, 2011 5:52:09 PM (4 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

DefaultSuperclassInstances
v7 v8 9 9 ('''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 depthlayers is (rightly!) greeted with howls of protest as an absence of superclass instances gives rise to breakage of the existing codebase. 10 10 11 == The proposal == 12 11 13 Concretely, the proposal is to 12 14 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. Yesto15 * 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 14 16 {{{ 15 17 class Functor f => Applicative f where … … 26 28 ff <*> fs = ff >>= \ f > fs >>= \ s > return (f s) 27 29 }}} 28 but noto30 but "no" to 29 31 {{{ 30 32 class (Tweedle dum, Tweedle dee) => Rum dum dee where … … 32 34 instance Tweedle dee where ... 33 35 }}} 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 35 38 {{{ 36 39 class Bar t[x] => Foo x where … … 39 42 instance C => Foo s where ... 40 43 }}} 41 we automatically acquire a default superclass instance44 we automatically acquire a default superclass instance 42 45 {{{ 43 46 instance C => Bar t[s] where ... 44 47 }}} 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 46 50 {{{ 47 51 instance Monad Blah where … … 49 53 ba >>= bf = ... 50 54 }}} 51 and acquire the Monad instance, along with fully formed Applicative and Functor instances. By requiring that intrinsic superclasses be classdistinct, we ensure that the distribution of methods to spawned instances is unambiguous. Moreover, local overrides beat the default. If we write55 and acquire the Monad instance, along with fully formed Applicative and Functor instances. By requiring that intrinsic superclasses be classdistinct, we ensure that the distribution of methods to spawned instances is unambiguous. Moreover, local overrides beat the default. If we write 52 56 {{{ 53 57 instance Monad Blah where … … 56 60 bs >> bt = ... 57 61 }}} 58 we override the default (>>) but keep the (<*>) in the spawned Applicative instance. 59 * to inhibit defaultspawning with the syntax 62 we override the default (>>) but keep the (<*>) in the spawned Applicative instance. 63 64 * To inhibit defaultspawning with the syntax 60 65 {{{ 61 66 instance Sub x where … … 63 68 hiding instance Super 64 69 }}} 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 write70 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 66 71 {{{ 67 72 instance Monad Blah where … … 73 78 traverse f bx = ...  inducing a default implementation of Functor 74 79 }}} 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. 76 81 77 * while we're about it, to allow multiheaded instance declarations for classdisjoint conjunctions, with the same semantics for constraint duplication and method distribution as for the defaults, so82 * While we're about it, to allow multiheaded instance declarations for classdisjoint conjunctions, with the same semantics for constraint duplication and method distribution as for the defaults, so 78 83 {{{ 79 84 instance S => (C x, C' x) where … … 81 86 methodOfC' = ... 82 87 }}} 83 is short for88 is short for 84 89 {{{ 85 90 instance S => C x where … … 88 93 methodOfC' = ... 89 94 }}} 95 90 96 This proposal fits handily with the [wiki:KindFact kind Fact proposal], which allows multiple constraints to be abbreviated by ordinary type synonyms. 91 97