Skip to content

Commit 2165d4a

Browse files
Merge pull request #452 from haskellfoundation/GHC-57396
Document GHC-57396
2 parents d1e0c29 + 4c4dd33 commit 2165d4a

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Linear types are not supported in FFI
3+
summary: Linear types are not supported when using GHC's FFI functionality
4+
severity: error
5+
introduced: 9.6.1
6+
---
7+
8+
If the extension `LinearTypes` is enabled, then programmers can write expressions which have the linear
9+
function type `a %1 -> b` for functions which use their argument exactly once.
10+
When calling external functions via GHC's FFI functionality, however, then it is not allowed to use a linear function type.
11+
12+
More information about this specific restriction can be found in the discussion in the [GHC issue tracker](https://gitlab.haskell.org/ghc/ghc/-/issues/18472).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{-# LANGUAGE LinearTypes #-}
2+
module LinearFFI where
3+
4+
import Foreign.Ptr
5+
6+
foreign import ccall "exp" c_exp :: Double -> Double
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{-# LANGUAGE LinearTypes #-}
2+
module LinearFFI where
3+
4+
import Foreign.Ptr
5+
6+
foreign import ccall "exp" c_exp :: Double %1 -> Double
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: Linear function type was used in foreign function call
3+
---
4+
5+
In this example the programmer tries to use a C function with the help of GHC's FFI system.
6+
The type given to the imported function, however, is not allowed.
7+
Only non-linear function types can be given to foreign functions.
8+
9+
```
10+
messages/GHC-57396/linear-ffi/before/LinearFFI.hs:6:1: error: [GHC-57396]
11+
• Unacceptable argument type in foreign declaration:
12+
Linear types are not supported in FFI declarations, see #18472
13+
• When checking declaration:
14+
foreign import ccall safe "exp" c_exp :: Double %1 -> Double
15+
|
16+
6 | foreign import ccall "exp" c_exp :: Double %1 -> Double
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
```

0 commit comments

Comments
 (0)