[MLton] Two questions about FFI types

Stephen Weeks MLton@mlton.org
Tue, 10 May 2005 10:29:14 -0700


> >   val a2v = _prim "Array_toVector": 'a array -> 'a vector;
...
> This doesn't quite work, as the opaque signature on CharArray and 
> CharVector hide the fact that their types are monomorphic instantiations 
> of the polymorphic array and vector type constructors. 

For the record, only CharArray hides the type.  char vector =
CharVector.vector = string (only the latter of the equalities is
mandated by the basis spec).  So, the following type checks.

----------------------------------------------------------------------
val a2v = _prim "Array_toVector": 'a array -> 'a vector;

val f = _import "f": char array -> unit;
   
val g: int -> string =
   fn n =>
   let
      val a = Array.array (n, #"\000")
      val () = f a
   in
      a2v a
   end
--------------------------------------------------------------------------------

This is not to say that this approach is better than using the _prim
that peeks through opacity.  It's a tradeoff on which unspecified
aspect of MLton you want to use: the fact that char vector = string or
that _prim works that way.  They seem equally unlikely to change to
me.