[MLton] Callback to function pointer?
Fri, 15 Jul 2005 18:10:45 -0400 (EDT)
> _import *: ptrTy -> cfTy; ptrTy -> cfTy
> So I think it makes sense to
> stick with _import * (which, by the way Matthew must have slipped the
> currying by me in my sleep :-).
I think the currying is very useful here, because the common scenario is
what appears in examples/ff/iimport.sml:
val double_to_double =
_import * : DynLink.fptr -> real -> real;
val sin_fptr = DynLink.dlsym (hndl, "sin")
val cos_fptr = DynLink.dlsym (hndl, "cos")
val tan_fptr = DynLink.dlsym (hndl, "tan")
val sin = double_to_double sin_fptr
val cos = double_to_double cos_fptr
val tan = double_to_double tan_fptr
> Stephen proposed:
> _symbol "symbol": cbTy; (unit -> cbTy) * (cbTy -> unit)
> _symbol *: ptrTy, cbTy; (ptrTy -> cbTy) * (ptrTy * cbTy -> unit)
My vote is for this proposal.
> o is not backward compatible
> o introduces a new keyword
It is an advanced, unsafe feature, so I think some breakage is o.k.
Likewise, at most it breaks _import "symbol": cbTy; and the undocumented
_import # "symbol" : ptrTy;
> o does not use currying
Sigh. But, I don't think it saves much in this scenario, since the common
case would be:
val (get_double, set_double) =
_symbol * : real;
val epsilon_ptr = DynLink.dlsym (hndl, "epsilon")
val get_epsilon = fn () => get_double epsilon_ptr
val set_epsilon = fn e => set_double (epsilon_ptr, e)
> One thing I don't like about any of the proposals is having to write
> the pointer type, since it is almost always MLton.Pointer.t.
I disagree. DynLib would like to use an opaque DynLib.fptr.