Revised FFI syntax + typing

Alastair Reid reid at cs.utah.edu
Sun May 6 14:15:21 EDT 2001


> Interesting language, but can anyone remind me what these
> #if etc are supposed to me - I can't find them in the
> Haskell report.

They're not?  
But I see code like that all over the place.

> There is no point in trying to fix a problem that H98 already
> introduced.  The H98 Committee in their infinite wisdom chose to
> have types with system-dependent sizes and I think, we should be as
> orthogonal as possible whether we like it or not.

But H98 doesn't have Word so I don't see a requirement to add it or to
provide ffi support for it.  

-- 
Alastair Reid        reid at cs.utah.edu        http://www.cs.utah.edu/~reid/

ps As I understand it, underspecifying the size of Int in Haskell 1.0
was largely to allow compilers to use one or two bits as tags to
distinguish boxed values (pointers) from unboxed values (ints, chars,
etc.).  In particular, this lets Haskell compilers generate Lisp code
(since Lisp compilers often use that GC trick and lack the type
information which would make it redundant).  No current Haskell
compilers use this trick (it's not very effective in lazy/polymorphic
languages).  Hugs comes close but, though it would be easier to
provide ints with restricted range, it opts for providing a full 32
bits.  (The decision to do this predates my involvement with Hugs.)

The other reason for doing it is the hope of going a little bit faster
on 64 bit machines.  I'm not sure if there actually is a performance
benefit or if it is significant.

pps I'm assuming that UShort and the like have system-dependent sizes
but I'm not objecting to them because it's just not possible to work
with C without making the types match up - Int8 and friends don't go
quite far enough towards speaking C's language.  Pretty much every ffi
interface I've ever written starts by figuring out the sizes of each
of the major C types and selecting the corresponding explicitly sized
Haskell type to represent it.




More information about the FFI mailing list