[MLton] Two questions about FFI types

Stephen Weeks MLton@mlton.org
Tue, 10 May 2005 08:15:26 -0700


> Why should the number of imports matter?  The end user of the mysql 
> library won't be affected -- they should be passing string option-s for 
> each argument that can either be a C string or NULL.  Granted, it is a bit 
> of annoying boilerplate, but I don't see why it makes (b) obviously 
> better.

I was referring to the fact that the number of imports is exponential
in the number of string-or-NULL arguments.

> Another variation on this, would be to statically (on the C side) allocate 
> a large enough char array and import its base address.  Then you don't 
> need to malloc and free each time.

SML with buffer overflow attacks.  Yippee!  :-)

> the opaque signature on CharArray and 
> CharVector hide the fact that their types are monomorphic instantiations 
> of the polymorphic array and vector type constructors.  Hence, applying 
> a2v to a CharArray.array is a type error.  Fortunately, _prim peers right 
> through opaque signatures, so you can import the primitive as:
> 
>   val a2v = _prim "Array_toVector": CharArray.array -> CharVector.vector;

Neat.