|
|
|
# closed classes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
closed classes are ones for which no more instances may be defined. these can be used to produce better error messages and to refine types.
|
|
|
|
|
|
|
|
|
|
|
|
## proposal
|
|
|
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
|
|
|
|
allow the closed keyword right after class.
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
class closed ... where
|
|
|
|
...
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
this will mean that even if the class is exported no one may declare more instances for it
|
|
|
|
|
|
|
|
## alternate, better proposal
|
|
|
|
|
|
|
|
|
|
|
|
specify it in the export list
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
module Foo(closed Foo(..)) where
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
this has the advantage that you can create instances in several modules in a private implementation then export them closed in the public interface. it also fits in nicely with the idea of explicit namespaces in the [ModuleSystem](module-system) and the readonly modifier in the [ReadonlyConstructors](readonly-constructors) proposal.
|
|
|
|
|
|
|
|
## pro
|
|
|
|
|
|
|
|
|
|
|
|
- compilers based on jhc's class system can take very good advantage of such declarations when optimizing.
|
|
|
|
- This sort of thing is often needed when doing phantom type and type class tricks.
|
|
|
|
- this is available in helium in order to increase the accuracy of error messages to good effect.
|
|
|
|
- syntax is similar to 'class alias' and 'class overlapping' proposals
|
|
|
|
|
|
|
|
## con
|
|
|
|
|
|
|
|
|
|
|
|
- a new language construct |