summaryrefslogtreecommitdiff
path: root/docs/users_guide/ffi-chap.xml
diff options
context:
space:
mode:
authorsimonpj@microsoft.com <unknown>2006-04-14 10:52:12 +0000
committersimonpj@microsoft.com <unknown>2006-04-14 10:52:12 +0000
commit284e6b500dd92bb132845c39ec1a9d8ef78c009a (patch)
treee74f5289909dc17a601a2956a169854765ffedc7 /docs/users_guide/ffi-chap.xml
parent48967672a6e999cda74a5a7e02059930ef794961 (diff)
downloadhaskell-284e6b500dd92bb132845c39ec1a9d8ef78c009a.tar.gz
Document newtype-unwrapping for IO in FFI
Diffstat (limited to 'docs/users_guide/ffi-chap.xml')
-rw-r--r--docs/users_guide/ffi-chap.xml25
1 files changed, 25 insertions, 0 deletions
diff --git a/docs/users_guide/ffi-chap.xml b/docs/users_guide/ffi-chap.xml
index e1374c4610..78c23f8f9e 100644
--- a/docs/users_guide/ffi-chap.xml
+++ b/docs/users_guide/ffi-chap.xml
@@ -54,6 +54,31 @@ the <option>-fglasgow-exts</option><indexterm><primary><option>-fglasgow-exts</o
and <literal>ByteArray#</literal>.</para>
</sect2>
+ <sect2>
+ <title>Newtype wrapping of the IO monad</title>
+ <para>The FFI spec requires the IO monad to appear in various places,
+ but it can sometimes be convenient to wrap the IO monad in a
+ <literal>newtype</literal>, thus:
+<programlisting>
+ newtype MyIO a = MIO (IO a)
+</programlisting>
+ (A reason for doing so might be to prevent the programmer from
+ calling arbitrary IO procedures in some part of the program.)
+</para>
+<para>The Haskell FFI already specifies that arguments and results of
+foreign imports and exports will be automatically unwrapped if they are
+newtypes (Section 3.2 of the FFI addendum). GHC extends the FFI by automatically unnwrapping any newtypes that
+wrap the IO monad itself.
+More precisely, wherever the FFI specification requires an IO type, GHC will
+accept any newtype-wrapping of an IO type. For example, these declarations are
+OK:
+<programlisting>
+ foreign import foo :: Int -> MyIO Int
+ foreign import "dynamic" baz :: (Int -> MyIO Int) -> CInt -> MyIO Int
+</programlisting>
+</para>
+ </sect2>
+
</sect1>
<sect1 id="sec-ffi-ghc">