Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > by-pkgid > 3575c686237628b9bdedf5f294fbd58c > files > 19

hugs98-20011215-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.6">
 <TITLE>The Hugs-GHC Extension Libraries: Foreign</TITLE>
 <LINK HREF="libs-15.html" REL=next>
 <LINK HREF="libs-13.html" REL=previous>
 <LINK HREF="libs.html#toc7" REL=contents>
</HEAD>
<BODY>
<A HREF="libs-15.html">Next</A>
<A HREF="libs-13.html">Previous</A>
<A HREF="libs.html#toc7">Contents</A>
<HR>
<H2><A NAME="sec:Foreign"></A> <A NAME="s7">7. Foreign</A></H2>

<P>
<P>This module provides the <CODE>ForeignObj</CODE> type, which is a Haskell
reference to an object in the outside world.  Foreign objects are
boxed versions of <CODE>Addr#</CODE>, the only reason for their existence is
so that they can be used with finalisers (see Section 
<@@ref>foreign-finalisersFinalisation for foreign objects</A>).
<P>
<BLOCKQUOTE><CODE>
<PRE>
module Foreign where
data ForeignObj  -- abstract, instance of: Eq

makeForeignObj  :: Addr{-object-} -> IO ForeignObj
writeForeignObj :: ForeignObj -> Addr{-new value-} -> IO ()
</PRE>
 
</CODE></BLOCKQUOTE>
<P>In addition to the above, the following operations for indexing via
a <CODE>ForeignObj</CODE> are also, mirrored on the same operations provided
over <CODE>Addr</CODE>s:
<P>
<BLOCKQUOTE><CODE>
<PRE>
indexCharOffForeignObj   :: ForeignObj -> Int -> Char
indexIntOffForeignObj    :: ForeignObj -> Int -> Int
indexAddrOffForeignObj   :: ForeignObj -> Int -> Addr
indexFloatOffForeignObj  :: ForeignObj -> Int -> Float
indexDoubleOffForeignObj :: ForeignObj -> Int -> Double
indexWord8OffForeignObj  :: ForeignObj -> Int -> Word8
indexWord16OffForeignObj :: ForeignObj -> Int -> Word16
indexWord32OffForeignObj :: ForeignObj -> Int -> Word32
indexWord64OffForeignObj :: ForeignObj -> Int -> Word64

indexInt8OffForeignObj  :: ForeignObj -> Int -> Int8
indexInt16OffForeignObj :: ForeignObj -> Int -> Int16
indexInt32OffForeignObj :: ForeignObj -> Int -> Int32
indexInt64OffForeignObj :: ForeignObj -> Int -> Int64

-- read value out of mutable memory
readCharOffForeignObj    :: ForeignObj -> Int -> IO Char
readIntOffForeignObj     :: ForeignObj -> Int -> IO Int
readAddrOffForeignObj    :: ForeignObj -> Int -> IO Addr
readFloatOffForeignObj   :: ForeignObj -> Int -> IO Float
readDoubleOffForeignObj  :: ForeignObj -> Int -> IO Double
readWord8OffForeignObj   :: ForeignObj -> Int -> IO Word8
readWord16OffForeignObj  :: ForeignObj -> Int -> IO Word16
readWord32OffForeignObj  :: ForeignObj -> Int -> IO Word32
readWord64OffForeignObj  :: ForeignObj -> Int -> IO Word64
readInt8OffForeignObj    :: ForeignObj -> Int -> IO Int8
readInt16OffForeignObj   :: ForeignObj -> Int -> IO Int16
readInt32OffForeignObj   :: ForeignObj -> Int -> IO Int32
readInt64OffForeignObj   :: ForeignObj -> Int -> IO Int64

writeCharOffForeignObj   :: ForeignObj -> Int -> Char   -> IO ()
writeIntOffForeignObj    :: ForeignObj -> Int -> Int    -> IO ()
writeAddrOffForeignObj   :: ForeignObj -> Int -> Addr   -> IO ()
writeFloatOffForeignObj  :: ForeignObj -> Int -> Float  -> IO ()
writeDoubleOffForeignObj :: ForeignObj -> Int -> Double -> IO ()
writeWord8OffForeignObj  :: ForeignObj -> Int -> Word8  -> IO ()
writeWord16OffForeignObj :: ForeignObj -> Int -> Word16 -> IO ()
writeWord32OffForeignObj :: ForeignObj -> Int -> Word32 -> IO ()
writeWord64OffForeignObj :: ForeignObj -> Int -> Word64 -> IO ()
writeInt8OffForeignObj   :: ForeignObj -> Int -> Int8   -> IO ()
writeInt16OffForeignObj  :: ForeignObj -> Int -> Int16  -> IO ()
writeInt32OffForeignObj  :: ForeignObj -> Int -> Int32  -> IO ()
writeInt64OffForeignObj  :: ForeignObj -> Int -> Int64  -> IO ()
</PRE>
</CODE></BLOCKQUOTE>
<P>
<HR>
<A HREF="libs-15.html">Next</A>
<A HREF="libs-13.html">Previous</A>
<A HREF="libs.html#toc7">Contents</A>
</BODY>
</HTML>