diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2019-05-29 11:52:02 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-05-31 23:56:27 -0400 |
commit | 45f88494293bea20cc3aca025ee6fe84087987ce (patch) | |
tree | 131f6175331925789d69f1d651e3463e21d4c98f /docs/users_guide | |
parent | 1d43d4a3e45d86261fa63591e99749cb7d3f68ed (diff) | |
download | haskell-45f88494293bea20cc3aca025ee6fe84087987ce.tar.gz |
Reject nested foralls in foreign imports (#16702)
This replaces a panic observed in #16702 with a simple error message
stating that nested `forall`s simply aren't allowed in the type
signature of a `foreign import` (at least, not at present).
Fixes #16702.
Diffstat (limited to 'docs/users_guide')
-rw-r--r-- | docs/users_guide/ffi-chap.rst | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/docs/users_guide/ffi-chap.rst b/docs/users_guide/ffi-chap.rst index b90b48a672..13ea352c8d 100644 --- a/docs/users_guide/ffi-chap.rst +++ b/docs/users_guide/ffi-chap.rst @@ -14,9 +14,10 @@ Foreign function interface (FFI) Allow use of the Haskell foreign function interface. -GHC (mostly) conforms to the Haskell Foreign Function Interface, whose -definition is part of the Haskell Report on -`http://www.haskell.org/ <http://www.haskell.org/>`__. +GHC (mostly) conforms to the Haskell Foreign Function Interface as specified +in the Haskell Report. Refer to the `relevant chapter +<https://www.haskell.org/onlinereport/haskell2010/haskellch8.html>_` +of the Haskell Report for more details. FFI support is enabled by default, but can be enabled or disabled explicitly with the :extension:`ForeignFunctionInterface` flag. @@ -102,6 +103,25 @@ OK: :: foreign import foo :: Int -> MyIO Int foreign import "dynamic" baz :: (Int -> MyIO Int) -> CInt -> MyIO Int +.. _ffi-foralls: + +Explicit ``forall``s in foreign types +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The type variables in the type of a foreign declaration may be quantified with +an explicit ``forall`` by using the :extension:`ExplicitForAll` language +extension, as in the following example: :: + + {-# LANGUAGE ExplicitForAll #-} + foreign import ccall "mmap" c_mmap :: forall a. CSize -> IO (Ptr a) + +Note that an explicit ``forall`` must appear at the front of the type signature +and is not permitted to appear nested within the type, as in the following +(erroneous) examples: :: + + foreign import ccall "mmap" c_mmap' :: CSize -> forall a. IO (Ptr a) + foreign import ccall quux :: (forall a. Ptr a) -> IO () + .. _ffi-prim: Primitive imports |