... | @@ -148,6 +148,9 @@ to inhibit the `Functor` instance arising from `Monad` but retain that from `Tra |
... | @@ -148,6 +148,9 @@ to inhibit the `Functor` instance arising from `Monad` but retain that from `Tra |
|
|
|
|
|
**Requirement 6** The meaning of an instance definition should be clear only from its class declaration (and those of its superclasses) and not deduced from the presence or absence of other instances.
|
|
**Requirement 6** The meaning of an instance definition should be clear only from its class declaration (and those of its superclasses) and not deduced from the presence or absence of other instances.
|
|
|
|
|
|
|
|
|
|
|
|
A helpful observation is that the language for describing which instances to generate from a given instance definition should be the same as the language for specifying which intrinsic superclass instances should be generated by default in a class declaration, because they are two manifestations of the same problem. In both cases, we need to perform a closure computation, tracing back from a given atomic constraint to find all the intrinsic superclasses which have not been explicitly excluded.
|
|
|
|
|
|
## Terminology and Notation
|
|
## Terminology and Notation
|
|
|
|
|
|
|
|
|
... | @@ -206,7 +209,7 @@ We can say what are the "intrinsic" superclasses of a class, with "immediate" an |
... | @@ -206,7 +209,7 @@ We can say what are the "intrinsic" superclasses of a class, with "immediate" an |
|
Of course, the above is an inductive definition, so it gives rise to a notion of **intrinsic superclass derivation**, being the explanation why some S is an intrinsic superclass of some C.
|
|
Of course, the above is an inductive definition, so it gives rise to a notion of **intrinsic superclass derivation**, being the explanation why some S is an intrinsic superclass of some C.
|
|
|
|
|
|
|
|
|
|
Every *closure* formula, F, has an **intrinsic closure**, IC(F), being the multiset of atomic formulae given by tracing each intrinsic superclass derivation of F's named class without passing through the classes explicitly listed after the `-` sign, substituting actual for formal parameters. E.g,
|
|
The *closure* formulae, above, explain how to compute which intrinsic superclasses we are bundling with a given class or instance. Every *closure* formula, F, has an **intrinsic closure**, IC(F), being the multiset of atomic formulae given by tracing each intrinsic superclass derivation of F's named class without passing through the classes explicitly listed after the `-` sign, substituting actual for formal parameters. E.g,
|
|
|
|
|
|
- IC(`Monad []`) = {`Monad []`, `Applicative []`, `Functor []`}
|
|
- IC(`Monad []`) = {`Monad []`, `Applicative []`, `Functor []`}
|
|
- IC(`Monad [] - Functor`) = {`Monad []`, `Applicative []`}
|
|
- IC(`Monad [] - Functor`) = {`Monad []`, `Applicative []`}
|
... | @@ -436,4 +439,4 @@ The same logic should clearly apply to `deriving` clauses, so that (e.g. for `Sq |
... | @@ -436,4 +439,4 @@ The same logic should clearly apply to `deriving` clauses, so that (e.g. for `Sq |
|
|
|
|
|
- `deriving Ord` gives `Ord a => Ord (Square a)` as usual and `Ord a => Eq (Square a)` with default implementation;
|
|
- `deriving Ord` gives `Ord a => Ord (Square a)` as usual and `Ord a => Eq (Square a)` with default implementation;
|
|
- `deriving (Ord, Eq) gives `Ord a =\> Ord (Square a)` and `Eq a =\> Eq (Square a)\`, with no pre-emption warning;
|
|
- `deriving (Ord, Eq) gives `Ord a =\> Ord (Square a)` and `Eq a =\> Eq (Square a)\`, with no pre-emption warning;
|
|
- `deriving (Ord - Eq) gives just `Ord a =\> Ord (Square a)` requiring a separate hand-rolled `Eq (Square a)\` instance. |
|
- `deriving (Ord - Eq)` gives just `Ord a => Ord (Square a)` requiring a separate hand-rolled `Eq (Square a)` instance. |