[MLton] MLton import headers

Wesley W. Terpstra wesley at terpstra.ca
Thu Oct 2 03:20:17 PDT 2008


Currently MLton outputs C import headers (ironically with
-export-header). I think it might also be useful to output an ML
import file.

One of the problems with using a library is that you need to know how
you are linking against it. Often programmers can get away without
knowing, but this breaks down on some combinations of operating
system, architecture, and definitions. One of the tasks the C import
header is to make the details transparent to the user.

When using a MLton generated library from another MLton program, there
is the same problem. _import "foo" public: ...; is appropriate for a
static link, while _import "foo" external: ...; is appropriate for a
dynamic link. I was thinking of an output file something like:

signature M1 =
  sig
    val m1_open : int * string vector -> unit;
    val m1_close : unit -> unit;
  end

structure STATIC_LINK_M1 :> M1 =
  struct
    val m1_open = _import "m1_open" public;
    val m1_close = _import "m1_close" public;
  end

structure DYNAMIC_LINK_M1 :> M1 =
  struct
    val m1_open = _import "m1_open" external;
    val m1_close = _import "m1_close" external;
  end

I have intentionally left out PART_OF_M1 because you're better off not
using the FFI in this case.

Thoughts?



More information about the MLton mailing list