Skip to content

Commit dcb5764

Browse files
authored
Merge pull request #449 from haskellfoundation/GHC-31574
Document GHC-31574
2 parents f9b1a05 + 1cdbabf commit dcb5764

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Illegal use of linear functions
3+
summary: The linear function type is used, but LinearTypes are not enabled
4+
severity: error
5+
introduced: 9.6.1
6+
---
7+
8+
Starting with version 9.0, GHC supports linear types.
9+
These types allow the programmer to express how often the argument to a function is used in the function body.
10+
For this reason, a new function type `a %1 -> b` has been introduced which stands for *linear* functions which use their argument of type `a` exactly once.
11+
In order to use these functions, however, the extension `LinearTypes` has to be enabled.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# LANGUAGE LinearTypes #-}
2+
module LinearIdentity where
3+
4+
linearIdentity :: a %1 -> a
5+
linearIdentity x = x
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
module LinearIdentity where
3+
4+
linearIdentity :: a %1 -> a
5+
linearIdentity x = x
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Linear identity function needs LinearTypes extension
3+
---
4+
5+
In this example, the programmer correctly implemented the identity function with a linear type signature.
6+
This type signature correctly states that the identity function uses its argument exactly once.
7+
In order to be able to use this type signature, the extension `LinearTypes` has to be enabled.
8+
9+
```
10+
messages/GHC-31574/linearIdentity/before/LinearIdentity.hs:3:21: error: [GHC-31574]
11+
Illegal use of linear functions
12+
Suggested fix: Perhaps you intended to use LinearTypes
13+
|
14+
3 | linearIdentity :: a %1 -> a
15+
|
16+
```

0 commit comments

Comments
 (0)