[MLton] FFI types

Henry Cejtin henry.cejtin@sbcglobal.net
Thu, 12 May 2005 23:24:48 -0500


Ah,  you  are  quite  right,  I  completely missed the fact that C code could
return an array by either having  one  passed  in  or  by  calling  _export'd
routines to make one.

Re  options  and  NULL,  I  agree  that you want to use ML code to test if an
xxx option  is  NONE  or  SOME.   My  notion  was  to  have  a  function   in
MLton.Pointer of type

        string option -> t

which consist of the code

        fn NONE => null
         | SOME str => ?cast-string-to-t? str

where  ?cast-string-to-t?  is  something  that  give  you  a  MLton.Pointer.t
pointing to the first character of its string  argument  (and  similarly  for
refs, arrays and vectors).

Using  this,  _export  would  expand any string option arguments to some glue
expression which called the above function on them  and  the  actual  _export
would  use  MLton.Pointer.t.   This way it would all be invisible to the user
and would handle the convention of NULL being NONE and non-NULL being SOME.

For results, you would do the same thing in reverse.

My impression, definitely not from a real understanding of the code, is  that
this would be rather easy and not a large change.  Am I missing something?