Skip to content

Commit

Permalink
Document GHC-15843
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-romes committed Jun 6, 2024
1 parent cc1f169 commit 4a23965
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module DifferentKinds where

data ATypeConstructor a b c = ATC a b c

-- The .hs-boot or .hsig module
module DifferentKinds where

data ATypeConstructor a b c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module DifferentKinds where

data ATypeConstructor a b c = ATC a b c

-- The .hs-boot or .hsig module
module DifferentKinds where

data ATypeConstructor a b
26 changes: 26 additions & 0 deletions message-index/messages/GHC-15843/differentKinds/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: The types have different kinds
---

The types have different kinds. If you are using kind declarations or
annotations, make sure these match. Alternatively, you may have given different
numbers of type arguments to the same type constructor -- make sure the number
of arguments match.

## Example error text

```
X.hs:3:1: error: [GHC-15843]
• Type constructor ‘X’ has conflicting definitions in the module
and its hs-boot file.
Main module: type X :: * -> *
data X a = X a
Boot file: type X :: *
data X
The types have different kinds.
• In the data type declaration for ‘X’
|
3 | data X a = X a
| ^^^^^^^^^^^^^^
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module DifferentRoles where

data D a

-- .hs-boot or .hsig boot
{-# LANGUAGE RoleAnnotations #-}
module DifferentRoles where

type role D phantom
data D a
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module DifferentRoles where

data D a

-- .hs-boot or .hsig boot
module DifferentRoles where

data D a

28 changes: 28 additions & 0 deletions message-index/messages/GHC-15843/differentRoles/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: The roles do not match
---

The [roles](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/roles.html)
of the type constructor arguments do not match. A typical reason for the roles
not to match is that, in `.hs-boot` and `.hsig` modules, the role of arguments
in the forward type declarations defaults to `representional`.

In the following example, the role of the type argument in the actual module is
`phantom`, because it doesn't occur in the RHS of the data declaration. Since
`representational` is inferred for the `hs-boot` declaration.

## Example error text

```
T9204.hs:7:1: error: [GHC-15843]
• Type constructor ‘D’ has conflicting definitions in the module
and its hs-boot file.
Main module: type role D phantom
type D :: * -> *
data D a
Boot file: type D :: * -> *
data D a
The roles do not match.
NB: roles on abstract types default to ‘representational’ in hs-boot files.
• In the data type declaration for ‘D’
```
29 changes: 29 additions & 0 deletions message-index/messages/GHC-15843/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: Type constructor has conflicting definitions in the module and its hs-boot/hsig file
summary: The type constructor in the module and the signature or boot module differ
severity: error
introduced: 9.6.1
---

The type constructor definitions in modules must agree with the cycle-breaking
`hs-boot` modules as well as with the Backpack `hsig` module interface files, if
any of the two exist.

Type constructor definitions in `hs-boot` modules and `hsig` files are typically
given by forward data declarations (data declarations without any data
constructors, only the type constructor is declared), as that is the whole
purpose of those two "interface-like modules".

Therefore, this error message likely comes up in one of two situations:

1. The kinds of type constructors differ in the interface module and in the
actual module.
2. The type constructor kinds match, but the *roles* of some of the type
arguments don't match.

The first situation can be typically be easily fixed by making sure the type
declaration in the boot/sig module has the same number of type arguments as the
declaration in the module and making sure any kind declarations are equal. The
second situation can normally be solved by given a type role declaration to the
type constructor. See the two examples below.

0 comments on commit 4a23965

Please sign in to comment.