| ... | ... | @@ -26,6 +26,42 @@ There are also interactions with [RankNTypes](rank-n-types) - a type synonym may |
|
|
|
Adopt GHC's approach to type synonym expansion.
|
|
|
|
|
|
|
|
|
|
|
|
## Design choices
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Should kind inference be done before, or after expanding type synonyms? That is, should a type synonym have a fixed kind or not?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Currently GHC does kind inference before expanding type synonyms, and gives each type synonym a fixed kind. The following program is rejected:
|
|
|
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
type T f a = f a
|
|
|
|
|
|
|
|
x :: T (T (,) Int) Float
|
|
|
|
x = (1,2.0)
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
gives
|
|
|
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
syn.hs:5:10:
|
|
|
|
`(,)' is not applied to enough type arguments
|
|
|
|
Expected kind `* -> *', but `(,)' has kind `* -> * -> *'
|
|
|
|
In the type `T (,) Int'
|
|
|
|
In the type `T (T (,) Int) Float'
|
|
|
|
In the type signature for `x':
|
|
|
|
x :: T (T (,) Int) Float
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
In favour of GHC's approach is that type errors are more likely to be given in terms of types that the programmer actually wrote. However, this does reject more programs, and perhaps it would be simpler to treat type synonyms uniformly as macros, without kinds?
|
|
|
|
|
|
|
|
|
|
|
|
## References
|
|
|
|
|
|
|
|
|
| ... | ... | @@ -50,4 +86,6 @@ Adopt GHC's approach to type synonym expansion. |
|
|
|
## Cons
|
|
|
|
|
|
|
|
|
|
|
|
- any? |
|
|
|
- It's so … syntactic.
|
|
|
|
- There are the usual worries about deferred checking leading to less
|
|
|
|
informative diagnostics. |