Skip to content

Commit d1e0c29

Browse files
Document GHC-13218 (#451)
* Document GHC-13218 * Update message-index/messages/GHC-13218/illegalKindSignature/index.md Co-authored-by: David Thrane Christiansen <[email protected]> * Add missing order field and title to example --------- Co-authored-by: David Thrane Christiansen <[email protected]>
1 parent 01337e0 commit d1e0c29

File tree

10 files changed

+100
-0
lines changed

10 files changed

+100
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{-# LANGUAGE LinearTypes, KindSignatures #-}
2+
module IllegalKindSignature where
3+
4+
data Void1 :: * -> *
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{-# LANGUAGE LinearTypes, KindSignatures #-}
2+
module IllegalKindSignature where
3+
4+
data Void1 :: * %1 -> *
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Illegal kind signature for Void1 data type
3+
order: 0
4+
---
5+
6+
In this example, the data type declaration for the `Void1` data type was annotated with the kind signature `* %1 -> *`.
7+
This would be a linear kind, which Haskell does not support - only types may be linear.
8+
The kind signature of the data type should be `* -> *`.
9+
10+
```
11+
messages/GHC-13218/illegalKindSignature/before/IllegalKindSignature.hs:4:1: error: [GHC-13218]
12+
• Illegal linear function in a kind: * %1 -> *
13+
• In the data type declaration for ‘Void1’
14+
|
15+
4 | data Void1 :: * %1 -> *
16+
| ^^^^^^^^^^
17+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE LinearTypes, KindSignatures, DataKinds #-}
2+
module IllegalKindSignatureDesugared where
3+
4+
import GHC.Exts
5+
import GHC.Types
6+
7+
data Void1 :: FUN Many Type Type
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE LinearTypes, KindSignatures, DataKinds #-}
2+
module IllegalKindSignatureDesugared where
3+
4+
import GHC.Exts
5+
import GHC.Types
6+
7+
data Void1 :: FUN One Type Type
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Illegal kind signature for Void1 data type
3+
order: 1
4+
---
5+
6+
This example is similar to the previous one, except that instead of the spelling `* %1 -> *`, the spelling `Fun One Type Type` was chosen.
7+
In this case, the signature should be `Fun Many Type Type` instead.
8+
9+
```
10+
messages/GHC-13218/illegalKindSignatureDesugared/before/IllegalKindSignatureDesugared.hs:7:1: error: [GHC-13218]
11+
• Illegal linear function in a kind: * %1 -> *
12+
• In the data type declaration for ‘Void1’
13+
|
14+
7 | data Void1 :: FUN One Type Type
15+
| ^^^^^^^^^^
16+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{-# LANGUAGE LinearTypes, KindSignatures, DataKinds #-}
2+
module IllegalStandaloneKindSignature where
3+
4+
import GHC.Exts
5+
import GHC.Types
6+
7+
type K = Type -> Type
8+
9+
data Void1 :: K
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{-# LANGUAGE LinearTypes, KindSignatures, DataKinds #-}
2+
module IllegalStandaloneKindSignature where
3+
4+
import GHC.Exts
5+
import GHC.Types
6+
7+
type K = Type %1 -> Type
8+
9+
data Void1 :: K
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Illegal kind signature for Void1 data type
3+
order: 2
4+
---
5+
6+
This example is similar to the previous two examples, except that the malformed kind was first declared as a type synonym.
7+
8+
```
9+
messages/GHC-13218/illegalStandaloneKindSignature/before/IllegalStandaloneKindSignature.hs:9:1: error: [GHC-13218]
10+
• Illegal linear function in a kind: * %1 -> *
11+
• In the expansion of type synonym ‘K’
12+
In the data type declaration for ‘Void1’
13+
|
14+
9 | data Void1 :: K
15+
| ^^^^^^^^^^
16+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Illegal linear function in kind
3+
summary: A linear function was used for a higher kind, which is not allowed
4+
severity: error
5+
introduced: 9.6.1
6+
---
7+
8+
Haskell supports higher-kinds.
9+
For example, the type constructor `List` has kind `* -> *`, which can also be written as `Type -> Type` if the module `Data.Kind` is imported.
10+
Since version 9.0, GHC also supports the linear function type `a %1 -> b` which stands for functions which use their argument of type `a` exactly once in their function body.
11+
But this restriction does not make sense if we try to apply it to higher kinds, and for this reason functions like `* %1 -> *` or `Type %1 -> Type` cannot be used as the kinds of data types.

0 commit comments

Comments
 (0)