Unboxed types and FFI (GHC Users Guide, Section 8.1.1)

Simon Marlow simonmar at microsoft.com
Wed Jan 4 07:45:20 EST 2006

Dimitry Golubovsky wrote:
> The section 8.1.1 of the GHC User's Guide says this:
> The following unboxed types may be used as basic foreign types (see
> FFI Addendum, Section 3.2): Int#, Word#, Char#, etc
> Does this mean that when declaring a foreign function import for a C function
> int fun(int)
> I may write
> foreign import ccall "bla.h fun"
> fun :: Int# -> Int#
> instead of using CInt?

Yes you can do this, but it's non-portable (of course).  In many cases 
GHC's optimiser will remove unnecessary boxing anyway.

> Are there any examples of using unboxed types with FFI?

Not any more, because nowadays we prefer to use the portable version 
instead.  There might be a few examples of passing MutableByteArray# 
around, though.


More information about the Glasgow-haskell-users mailing list