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

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? Are there any examples of using unboxed types with FFI? -- Dimitry Golubovsky Anywhere on the Web

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. Cheers, Simon
participants (2)
-
Dimitry Golubovsky
-
Simon Marlow