Skip to content

Commit 01337e0

Browse files
Document GHC-59840 (#450)
* Document GHC-59840 * Apply suggestions from code review Co-authored-by: David Thrane Christiansen <[email protected]> * Apply suggestion from code review --------- Co-authored-by: David Thrane Christiansen <[email protected]>
1 parent dcb5764 commit 01337e0

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: GHC does not support GADTs or type families which witness equality of multiplicities
3+
summary: GHC does not support GADTs or type families which witness equality of multiplicities
4+
severity: error
5+
introduced: 9.6.1
6+
---
7+
8+
There are two features which GHC supports, and whose interaction is problematic and leads to this error:
9+
10+
- Programming constructs which build upon the type equality constraint `a ~ b`, such as GADTs and type families.
11+
- Linear types, which supports functions like `a %m -> b`. In this function type `m` stands for a *multiplicity* which can be either `One`(also written `1`) or `Many`, which determines how often the argument to the function may be used in the body of the function.
12+
13+
Problems arise when the type equality constraint `a ~ b` is used for multiplicities, i.e. when we encounter equalities like `m1 ~ m2`.
14+
Until the interaction between equality constraints and multiplicities is better understood, GHC decides to not support equalities between multiplicities, or features which require them.
15+
16+
More information about this particular interaction can be found on the [GHC issue tracker](https://gitlab.haskell.org/ghc/ghc/-/issues/19517).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module LinearPolyType where
2+
3+
-- This program cannot currently be written
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{-# LANGUAGE LinearTypes, GADTs, KindSignatures, DataKinds, TypeFamilies, PolyKinds #-}
2+
module LinearPolyType where
3+
4+
import GHC.Types
5+
data SBool :: Bool -> Type where
6+
STrue :: SBool True
7+
SFalse :: SBool False
8+
9+
type family If b t f where
10+
If True t _ = t
11+
If False _ f = f
12+
13+
dep :: SBool b -> Int %(If b One Many) -> Int
14+
dep STrue x = x
15+
dep SFalse _ = 0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: Computing a multiplicity with a type family and GADT is not supported
3+
---
4+
5+
This example of an interaction between multiplicities and type equalities was discussed in the[GHC proposal](https://github.com/ghc-proposals/ghc-proposals/pull/111#issuecomment-438125526) which introduced linear types.
6+
There is no theoretical problem with this program, but the type inference mechanisms that GHC currently uses cannot typecheck it.
7+
8+
```
9+
messages/GHC-59840/linearPolyType/before/LinearPolyType.hs:14:1: error: [GHC-59840]
10+
GHC bug #19517: GHC currently does not support programs using GADTs or type families to witness equality of multiplicities
11+
|
12+
14 | dep STrue x = x
13+
| ^^^^^^^^^^^^^^^...
14+
```

0 commit comments

Comments
 (0)