Skip to content

Commit 08d81f5

Browse files
committed
Document GHC-15843
1 parent c22e716 commit 08d81f5

File tree

7 files changed

+119
-0
lines changed

7 files changed

+119
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module DifferentKinds where
2+
3+
data ATypeConstructor a b c = ATC a b c
4+
5+
-- The .hs-boot or .hsig module
6+
module DifferentKinds where
7+
8+
data ATypeConstructor a b c
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module DifferentKinds where
2+
3+
data ATypeConstructor a b c = ATC a b c
4+
5+
-- The .hs-boot or .hsig module
6+
module DifferentKinds where
7+
8+
data ATypeConstructor a b
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: The types have different kinds
3+
---
4+
5+
The types have different kinds. If you are using kind declarations or
6+
annotations, make sure these match. Alternatively, you may have given different
7+
numbers of type arguments to the same type constructor -- make sure the number
8+
of arguments match.
9+
10+
## Example error text
11+
12+
```
13+
X.hs:3:1: error: [GHC-15843]
14+
• Type constructor ‘X’ has conflicting definitions in the module
15+
and its hs-boot file.
16+
Main module: type X :: * -> *
17+
data X a = X a
18+
Boot file: type X :: *
19+
data X
20+
The types have different kinds.
21+
• In the data type declaration for ‘X’
22+
|
23+
3 | data X a = X a
24+
| ^^^^^^^^^^^^^^
25+
```
26+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module DifferentRoles where
2+
3+
data D a
4+
5+
-- .hs-boot or .hsig boot
6+
{-# LANGUAGE RoleAnnotations #-}
7+
module DifferentRoles where
8+
9+
type role D phantom
10+
data D a
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module DifferentRoles where
2+
3+
data D a
4+
5+
-- .hs-boot or .hsig boot
6+
module DifferentRoles where
7+
8+
data D a
9+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: The roles do not match
3+
---
4+
5+
The [roles](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/roles.html)
6+
of the type constructor arguments do not match. A typical reason for the roles
7+
not to match is that, in `.hs-boot` and `.hsig` modules, the role of arguments
8+
in the forward type declarations defaults to `representional`.
9+
10+
In the following example, the role of the type argument in the actual module is
11+
`phantom`, because it doesn't occur in the RHS of the data declaration. Since
12+
`representational` is inferred for the `hs-boot` declaration.
13+
14+
## Example error text
15+
16+
```
17+
T9204.hs:7:1: error: [GHC-15843]
18+
• Type constructor ‘D’ has conflicting definitions in the module
19+
and its hs-boot file.
20+
Main module: type role D phantom
21+
type D :: * -> *
22+
data D a
23+
Boot file: type D :: * -> *
24+
data D a
25+
The roles do not match.
26+
NB: roles on abstract types default to ‘representational’ in hs-boot files.
27+
• In the data type declaration for ‘D’
28+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Type constructor has conflicting definitions in the module and its hs-boot/hsig file
3+
summary: The type constructor in the module and the signature in the boot module differ
4+
severity: error
5+
introduced: 9.6.1
6+
---
7+
8+
The type constructor definitions in modules must agree with the cycle-breaking
9+
`hs-boot` modules as well as with the Backpack `hsig` module interface files, if
10+
any of the two exist.
11+
12+
Type constructor definitions in [`hs-boot` modules](https://downloads.haskell.org/ghc/9.12.1/docs/users_guide/separate_compilation.html#mutually-recursive-modules-and-hs-boot-files)
13+
and [`hsig` files](https://downloads.haskell.org/ghc/9.12.1/docs/users_guide/separate_compilation.html#module-signatures) are typically
14+
given by forward data declarations (data declarations without any data
15+
constructors, only the type constructor is declared), as that is the whole
16+
purpose of those two "interface-like modules".
17+
18+
Therefore, this error message likely comes up in one of two situations:
19+
20+
1. The kinds of type constructors differ in the interface module and in the
21+
actual module.
22+
2. The type constructor kinds match, but the *roles* of some of the type
23+
arguments don't match.
24+
25+
The first situation can be typically be easily fixed by making sure the type
26+
declaration in the boot/sig module has the same number of type arguments as the
27+
declaration in the module and making sure any kind declarations are equal. The
28+
second situation can normally be solved by given a type role declaration to the
29+
type constructor. See the two examples below.
30+

0 commit comments

Comments
 (0)