[MLton-user] FFI and finalizable values

Stephen Weeks sweeks@sweeks.com
Tue, 16 Dec 2003 12:08:35 -0800


> In my program nested use of withValue occurs in a situation where
> types are coming behind :>. In that case each type needs its own
> withValue, therefore I would not find withValue2 usefull.  I was
> also looking to eliminate a function giving access to withValue,
> since FFI can look through :>.

Ah.  If I understand correctly, you are hiding a finalizable type
behind a :>.  Would it help to expose the fact that the type is
finalizable without exposing the contents?  For example:

structure S1:>
   sig
      type u
      type t = u Finalizable.t
   end =
   struct
      type u = Pointer.t
      type t = u Finalizable.t
   end

Then, you can use withValue (and withValue2) on S1.t, and even could
use type u with the FFI (because it looks through :>).  So, the
following would work.

val f = _import "f": S1.u -> unit;
val f: S1.t -> unit =
   fn t => withValue (t, f)