[MLton] Two questions about FFI types

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


> I don't know of any cleaner way given the way things are currently 
> implemented.  I ran into a very small version of this issue with some of 
> the networking functionality of the Basis Library:
> 
> http://mlton.org/pipermail/mlton/2002-December/022923.html

I am pleased to see I came up with the same empty-string solution back
then :-)

  http://mlton.org/pipermail/mlton/2002-December/022924.html

This should be added to the FAQ.

> If you want to play even faster and looser, you could do
> 
> let
>   var arr = Unsafe.CharArray.create n
>   val f = _import "f": CharArray.array -> unit ;
>   val () = f arr
>   val vec = Unsafe.CharVector.fromArray arr
> in
>   ... vec ...
> end
> 
> which won't even bother initializing the array (which is fine for a 
> character array, as it has no internal pointers). 

Good idea.

Maybe there should be a page on the wiki with FFI advice, starting
with these tricks.