FFI Report comments

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Tue Aug 21 06:45:18 EDT 2001


Manuel,

Here are my comments on the draft FFI Report itself.  It looks very
good to me, and there are just a few things to mention.

Lexical Structure
~~~~~~~~~~~~~~~~~
The lexical syntax adds 'foreign' as a keyword (reservedid).  I'm not
entirely convinced this is necessary.  Certainly in nhc98 we treat
'foreign' as just a specialid, and so like with other specialids you
can name a variable 'foreign' if you wish.  In other words, is there
any real reason to exclude the possibility of

    module F (foreign, as) where

    foreign :: X -> Y
    foreign ... = ...

    foreign import ccall "something" as :: CInt -> CInt -> CInt

which nhc98 currently accepts, but ghc -fglasgow-exts rejects?


Standard C Calls
~~~~~~~~~~~~~~~~
The productions

    fdecl  -> 'import' callconv [safety] entity var '::' ftype
    entity -> " ['static'] [fname] ['&'] ['['lib']'] [cid] "

suggest that the entity string must always be present, but could be
"".  I was wondering if there is any real difficulty in permitting
an empty entity string to be omitted altogether?  The idea would be
to be able to write

    foreign import ccall sin :: CFloat -> CFloat

as at present rather than

    foreign import ccall "" sin :: CFloat -> CFloat

It isn't a big deal, and it might be worth enforcing the literal string
quotes just for uniformity, but I thought I'd raise the issue anyway.


Int and Word
~~~~~~~~~~~~
You want to drop the assertion that "arithmetic is performed
modulo 2^n" for sized Int and Word types, on the grounds that this
doesn't hold for Int.  But Int is not of fixed size, so how could it
require modulo arithmetic!  I happen to think the fact that Int is of
unspecified size >30 bits, with undefined behaviour on overflow, was
something of a mistake in Haskell.  Now that we have the opportunity
to define a sensible overflow behaviour for fixed size types, I think
we should take it.


module Ptr
~~~~~~~~~~
The statement "alignPtr yields the next higher address that fulfills
the alignment constraint"  slightly conflicts with the following one
that "this operation is idempotent".  I think the first statement
really means to say "alignPtr yields an address, the same or next
higher, that fulfills the alignment constraint".


module StablePtr
~~~~~~~~~~~~~~~~
It seems a little strange that there is an instance of Storable
for StablePtr, yet we are forbidden to use the methods of Storable
to dereference a StablePtr.  In other words, I'm not quite clear on
exactly what is being forbidden.


C-Specific Marshalling
~~~~~~~~~~~~~~~~~~~~~~
HS_FLOAT_ROUND is called HS_FLOAT_ROUNDS in table 3.


Typos
~~~~~
There are a few typos and mis-spellings.  Would it be easiest for
someone like me to fix these directly via CVS, or is it better to
just give you a list privately?  I must admit that my experience of
using CVS for LaTeX documents was not a happy one, compared to how
useful it is for source code.

Regards,
    Malcolm




More information about the FFI mailing list