| | 187 | === Details === |
| | 188 | |
| | 189 | Each default superclass instance declaration in a `class` declaration must be for |
| | 190 | a distinct class. So one of these is OK and the other is not: |
| | 191 | {{{ |
| | 192 | -- This is ILLEGAL |
| | 193 | class (Tweedle dum, Tweedle dee) => Rum dum dee where |
| | 194 | instance Tweedle dum where ... |
| | 195 | instance Tweedle dee where ... |
| | 196 | |
| | 197 | -- But this is OK |
| | 198 | class (Tweedle dum, Tweedle dee) => Rum dum dee where |
| | 199 | instance Tweedle dee where ... |
| | 200 | }}} |
| | 201 | By requiring that intrinsic superclasses be class-distinct, we ensure that the distribution of methods to spawned instances is unambiguous. |
| | 202 | |
| | 203 | === Flags === |
| | 204 | |
| | 205 | The declaration of a class with a default superclass instance would require a language extension flag; but the ''instances'' of such a class would not. Again Design Goal 1 means that we want to impact client code as little as possible. |
| | 206 | |
| | 207 | --------------------------- |
| | 208 | == Possible variations == |
| | 209 | |
| | 210 | === The design of the opt-out mechanism === |
| | 211 | |
| | 212 | The [ http://www.haskell.org/haskellwiki/Superclass_defaults superclass default proposal] deals with the question of opt-outs by intead requiring you to opt ''in''. A `Monad` instance would look like |
| | 213 | {{{ |
| | 214 | instance (Functor T, Applicative T, Monad T) where |
| | 215 | (>>=) = ...blah... |
| | 216 | return = ...bleh... |
| | 217 | }}} |
| | 218 | where we explicitly ask the compiler to generate an instance of `Applicative T` and `Functor T`. The disadvantage is that you have to know to do so, which contradicts Design Goal 1. |
| | 219 | |
| 259 | | == Details == |
| 260 | | |
| 261 | | Each default superclass instance declaration in a `class` declaration must be for |
| 262 | | a distinct class. So one of these is OK and the other is not: |
| 263 | | {{{ |
| 264 | | -- This is ILLEGAL |
| 265 | | class (Tweedle dum, Tweedle dee) => Rum dum dee where |
| 266 | | instance Tweedle dum where ... |
| 267 | | instance Tweedle dee where ... |
| 268 | | |
| 269 | | -- But this is OK |
| 270 | | class (Tweedle dum, Tweedle dee) => Rum dum dee where |
| 271 | | instance Tweedle dee where ... |
| 272 | | }}} |
| 273 | | By requiring that intrinsic superclasses be class-distinct, we ensure that the distribution of methods to spawned instances is unambiguous. |
| 274 | | |
| | 302 | |