Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
jberryman
GHC
Commits
71f50414
Commit
71f50414
authored
Mar 14, 2002
by
simonpj
Browse files
[project @ 2002-03-14 15:49:36 by simonpj]
Documentation about type system extensions
parent
b9312420
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
ghc/docs/users_guide/glasgow_exts.sgml
View file @
71f50414
This diff is collapsed.
Click to expand it.
ghc/docs/users_guide/primitives.sgml
View file @
71f50414
...
...
@@ -1107,6 +1107,101 @@ putMVar# :: SynchVar# s elt -> State# s -> State# s
</sect2>
<sect2 id="glasgow-prim-arrays">
<title>Primitive arrays, mutable and otherwise
</title>
<para>
<indexterm><primary>primitive arrays (Glasgow extension)</primary></indexterm>
<indexterm><primary>arrays, primitive (Glasgow extension)</primary></indexterm>
</para>
<para>
GHC knows about quite a few flavours of Large Swathes of Bytes.
</para>
<para>
First, GHC distinguishes between primitive arrays of (boxed) Haskell
objects (type <literal>Array# obj</literal>) and primitive arrays of bytes (type
<literal>ByteArray#</literal>).
</para>
<para>
Second, it distinguishes between…
<variablelist>
<varlistentry>
<term>Immutable:</term>
<listitem>
<para>
Arrays that do not change (as with “standard” Haskell arrays); you
can only read from them. Obviously, they do not need the care and
attention of the state-transformer monad.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Mutable:</term>
<listitem>
<para>
Arrays that may be changed or “mutated.” All the operations on them
live within the state-transformer monad and the updates happen
<emphasis>in-place</emphasis>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>“Static” (in C land):</term>
<listitem>
<para>
A C routine may pass an <literal>Addr#</literal> pointer back into Haskell land. There
are then primitive operations with which you may merrily grab values
over in C land, by indexing off the “static” pointer.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>“Stable” pointers:</term>
<listitem>
<para>
If, for some reason, you wish to hand a Haskell pointer (i.e.,
<emphasis>not</emphasis> an unboxed value) to a C routine, you first make the
pointer “stable,” so that the garbage collector won't forget that it
exists. That is, GHC provides a safe way to pass Haskell pointers to
C.
</para>
<para>
Please see <xref LinkEnd="sec-stable-pointers"> for more details.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>“Foreign objects”:</term>
<listitem>
<para>
A “foreign object” is a safe way to pass an external object (a
C-allocated pointer, say) to Haskell and have Haskell do the Right
Thing when it no longer references the object. So, for example, C
could pass a large bitmap over to Haskell and say “please free this
memory when you're done with it.”
</para>
<para>
Please see <xref LinkEnd="sec-ForeignObj"> for more details.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
The libraries documentatation gives more details on all these
“primitive array” types and the operations on them.
</para>
</sect2>
</sect1>
<!-- Emacs stuff:
...
...
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