[MLton] Callback to function pointer?

Matthew Fluet fluet@cs.cornell.edu
Wed, 13 Jul 2005 09:08:03 -0400 (EDT)

> > MLton.Pointer.t is the only reasonable "expandOpaque" primitive
> > type, but it can still be useful to import an address at an opaque
> > SML type.
> Makes sense.  I slightly lean toward _address (with the type
> annotation) over "_import #" or "_import &".  But only slightly.

For FFI _import, we currently have the following:

  (* A. fetch a simple FFI object (when evaluated) *)
  _import "name" : ffiTy;

  (* B. call a function FFI object (when applied) *)
  _import "name" : argTy -> resTy;  

  (* C. address of an FFI object (when evaluated) *)
  _import # "name" : ptrTy;

  (* D. call a function through a pointer (when applied) *)
  _import * : ptrTy -> (argTy -> resTy);

I'm open to suggestions for better names or syntax.  There is a suggestion 
to replace C with

   _address "name" : ptrTy;

It does appear that there is a significant difference between A and B/D 
and I wonder if that is worth making explicit by a different syntax.  
Some other things of note: C and D parse into distinct AST nodes, while 
A/B parse into the same AST node.  Hence, the elaborator needs to check 
whether the expanded type annotation is an arrow to determine how to treat 
an A/B import AST node.