ANN: H98 FFI Addendum 1.0, Release Candidate 10

Alastair Reid alastair at reid-consulting-uk.ltd.uk
Mon Jun 2 07:33:19 EDT 2003


On Monday 02 June 2003 11:14 am, Malcolm Wallace wrote:
> How about something like:
>
>   The declaration
>       data T
>   declares an abstract datatype T, whose values and operations are
>   defined external to the Haskell language.  Values of T follow
>   the semantics of the foreign language, in particular, with respect
>   to mutability and the admission of the undefined value.

I don't think we have much choice about whether undefined values are part of 
the type.  If you can create a value of that type:

  x <- derefPtr (px :: Ptr T)

then you can create a thunk of that type:

  let y = if <expression> then x else y

and that thunk can be bottom.

> This raises the question of whether it should be possible to declare
> foreign functions directly over such types, [...]  However,
> I know that nhc98 internally at least uses the former style in order
> to implement built-in types like arrays, big integers, etc.

Hugs implements its builtin types this way too (and did so long before the ffi 
came along).  It works because Hugs magically knows how toi implement Int, 
Float, etc. - it knows about any typechecking rules and, most importantly, it 
knows how to represent and marshall values of builtin types.  If all the 
compiler is given is:

  data T

where T is not a builtin type, the compiler can't possible know how to 
represent or marshall it.  (And since we can already do that using 'newtype T 
= MkT Int8' I don't think we need to add another mechanism.)

Although it is similar, I think

  data Int

with a builtin type is a different thing from what we're doing when we write:

  data T

for some foreign type.

--
Alastair Reid



More information about the FFI mailing list