|
|
|
# Empty data declarations
|
|
|
|
|
|
|
|
**Ticket:**[\#25](https://gitlab.haskell.org//haskell/prime/issues/25)
|
|
|
|
|
|
|
|
## Brief Explanation
|
|
|
|
|
|
|
|
|
|
|
|
# Proposal: [EmptyDataDecls](empty-data-decls)
|
|
|
|
|
|
|
|
<table><tr><th> Ticket </th>
|
|
|
|
<th>[\#25](https://gitlab.haskell.org//haskell/prime/issues/25)</th></tr>
|
|
|
|
<tr><th> Dependencies </th>
|
|
|
|
<th> names of other proposals on which this one depends
|
|
|
|
</th></tr>
|
|
|
|
<tr><th> Related </th>
|
|
|
|
<th>
|
|
|
|
|
|
|
|
<table><tr><th>[\#85](https://gitlab.haskell.org//haskell/prime/issues/85)</th>
|
|
|
|
<td>more liberal kind inference</td></tr></table>
|
|
|
|
|
|
|
|
<table><tr><th>[\#84](https://gitlab.haskell.org//haskell/prime/issues/84)</th>
|
|
|
|
<td>Kind Annotations</td></tr></table>
|
|
|
|
|
|
|
|
<table><tr><th>[\#78](https://gitlab.haskell.org//haskell/prime/issues/78)</th>
|
|
|
|
<td>Add infix type constructors</td></tr></table>
|
|
|
|
|
|
|
|
Compiler support GHC \[ full (flagname) \| partial (flagname) (comments) \| none \]
|
|
|
|
nhc98 \[ full (flagname) \| partial (flagname) (comments) \| none \]
|
|
|
|
Hugs \[ full (flagname) \| partial (flagname) (comments) \| none \]
|
|
|
|
UHC \[ full (flagname) \| partial (flagname) (comments) \| none \]
|
|
|
|
JHC \[ full (flagname) \| partial (flagname) (comments) \| none \]
|
|
|
|
LHC \[ full (flagname) \| partial (flagname) (comments) \| none \]
|
|
|
|
Summary
|
|
|
|
Allow data declarations with no constructors.
|
|
|
|
Description
|
|
|
|
The proposal is to allow empty `data` declarations, i.e. data types without any
|
|
|
|
constructors. Syntactically, it is basically just a matter of making the
|
|
|
|
"`=`*constrs*" part optional in the context free syntax. Semantically,
|
|
|
|
the result is a type (once the type constructor has been fully applied)
|
|
|
|
whose only element is bottom. Examples (assuming
|
|
|
|
[Infix Type Constructors](infix-type-constructors) is adopted):
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
data S
|
|
|
|
|
|
|
|
data T a
|
|
|
|
|
|
|
|
data a :*: b
|
|
|
|
data a :\*: b
|
|
|
|
|
|
|
|
data (a :**: b) c
|
|
|
|
```
|
|
|
|
|
|
|
|
data (a :\*\*: b) c
|
|
|
|
[Kind inference](kind-inference) will of course be carried out for types constructors
|
|
|
|
introduced by empty declarations just as for any other type constructors according to
|
|
|
|
whatever rules are adopted. Unless there are further constraints, the kinds of the
|
|
|
|
constructors above would be
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
S :: *
|
|
|
|
T :: * -> *
|
|
|
|
(:*:) :: * -> * -> *
|
|
|
|
(:**:) :: * -> * -> * -> *
|
|
|
|
```
|
|
|
|
|
|
|
|
S :: \*
|
|
|
|
T :: \* -\> \*
|
|
|
|
(:\*:) :: \* -\> \* -\> \*
|
|
|
|
(:\*\*:) :: \* -\> \* -\> \* -\> \*
|
|
|
|
|
|
|
|
If [kind annotations](kind-annotations) are adopted, they should obviously also apply
|
|
|
|
to empty declarations. They would possibly be a little more important for empty declarations,
|
| ... | ... | @@ -45,11 +58,9 @@ is adopted. [Polymorphic kinds](kind-inference) would make this point moot, thou |
|
|
|
annotations then never would be needed, unless it is decided that kind annotations still would
|
|
|
|
be good documentation.
|
|
|
|
|
|
|
|
|
|
|
|
Note that contexts of course also would be allowed, but, as there are no data constructors, their
|
|
|
|
only impact would be on the inferred kind.
|
|
|
|
|
|
|
|
|
|
|
|
The only real issue is whether or not to allow the optional `deriving` clause after an empty declaration,
|
|
|
|
and, if not, on what stage to rule them out. Clearly, as there are no data constructors over which to
|
|
|
|
define functions, derived instances would (for consistency) have to be everywhere undefined. GHC seems
|
| ... | ... | @@ -57,17 +68,13 @@ to syntactically allow a `deriving` clause after an empty data declaration, but |
|
|
|
contextual error since no interesting instances can be defined. Presumably the reasoning was that this
|
|
|
|
gives a more regular syntax and better error messages than ruling out deriving for empty declarations
|
|
|
|
syntactically. But the point is that there is a choice.
|
|
|
|
A simple and natural generalisation of data declarations, seemingly without any hidden complications.
|
|
|
|
References[ http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html\#nullary-types](http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html#nullary-types) GHC documentation.
|
|
|
|
Report Delta
|
|
|
|
The changes to the report necessary to implement the proposal. Required for a proposal to move to the "accepted" state.
|
|
|
|
Download in other formats:[Plain Text](/wiki/EmptyDataDecls?version=6&format=txt)[](http://trac.edgewall.org/)Powered by [Trac 1.2.2](/about)
|
|
|
|
|
|
|
|
## References
|
|
|
|
|
|
|
|
- [ http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html\#nullary-types](http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html#nullary-types) GHC documentation.
|
|
|
|
-
|
|
|
|
|
|
|
|
<table><tr><th>[\#85](https://gitlab.haskell.org//haskell/prime/issues/85)</th>
|
|
|
|
<td>more liberal kind inference</td></tr></table>
|
|
|
|
|
|
|
|
[\#84](https://gitlab.haskell.org//haskell/prime/issues/84)Kind Annotations[\#78](https://gitlab.haskell.org//haskell/prime/issues/78)Add infix type constructorsProsA simple and natural generalisation of data declarations, seemingly without any hidden complications.
|
|
|
|
ConsDownload in other formats:[Plain Text](/wiki/EmptyDataDecls?version=5&format=txt)[](http://trac.edgewall.org/)Powered by [Trac 1.2.2](/about)
|
|
|
|
By [Edgewall Software](http://www.edgewall.org/).Visit the Trac open source project at
|
|
|
|
[http://trac.edgewall.com/](http://trac.edgewall.com/)
|
|
|
|
|
|
|
|
By [Edgewall Software](http://www.edgewall.org/).Visit the Trac open source project at
|
|
|
|
[http://trac.edgewall.com/](http://trac.edgewall.com/) |
|
|
\ No newline at end of file |
|
|
|
</th></tr></table> |
|
|
\ No newline at end of file |