Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
4,322
Issues
4,322
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
361
Merge Requests
361
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
284e6b50
Commit
284e6b50
authored
Apr 14, 2006
by
simonpj@microsoft.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document newtype-unwrapping for IO in FFI
parent
48967672
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
docs/users_guide/ffi-chap.xml
docs/users_guide/ffi-chap.xml
+25
-0
No files found.
docs/users_guide/ffi-chap.xml
View file @
284e6b50
...
...
@@ -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"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment