Changes between Version 15 and Version 16 of DefaultSuperclassInstances
- Timestamp:
- 08/15/11 01:42:52 (22 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DefaultSuperclassInstances
v15 v16 25 25 compatibility in relative silence is the motivation for an opt-in 26 26 default. 27 28 == Design goals == 29 30 A major design goal is this: 31 32 * '''Design goal 1''': a class C can be re-factored into a class C with a superclass S, without disturbing any clients. 33 34 The difficulty is that if you start with 35 {{{ 36 class X a where 37 f :: ... 38 g :: ... 39 }}} 40 and lots of clients write instances of `X` and functions that use it: 41 {{{ 42 instance X ClientType 43 f = ...blah... 44 g = ...blah... 45 46 foo :: X a => ... 47 foo = ... 48 }}} 49 Now you want to refactor `X` thus: 50 {{{ 51 class Y a where 52 f :: ... 53 class Y a => X a where 54 g :: ... 55 }}} 56 Design goal 1 is that this change should not force clients to change their code. Haskell 98 does not satisfy this goal. In Haskell 98 the client function `foo` is fine unmodified, but the instance declaration would have to be split into two. 27 57 28 58 == The proposal == … … 187 217 dangerous tendency to be permanent. 188 218 219 == Other designs == 220 221 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 222 {{{ 223 instance (Applicative m, Monad m) where 224 (>>=) = ...blah... 225 (<*) = ...bleh... 226 }}} 227 where we explicitly ask the compiler to generate an instance of `Applicative`. The disadvantage is that you have to know to do so, which contracts Design Goal 1. 228 189 229 == Multi-headed instance declarations == 190 230
