[MLton] bool and MLton FFI
skaller
skaller@users.sourceforge.net
Sat, 24 Jun 2006 00:33:44 +1000
On Fri, 2006-06-23 at 14:27 +0200, Wesley W. Terpstra wrote:
> I disagree here. We should start encouraging users to use _import
> like this:
> _import "foo" : C_Int.t * C_Long.t * Int32.t-> C_Bool.t
> for the function:
> extern bool foo(int x, long y, int32_t z);
> Otherwise their code won't be portable.
This is naive. No realistic libraries provide functions like that.
Real library API's look like:
GLint GLgetStatus(GLint);
which means if you're trying to model the C function correctly
in a portable manner, you have NO choice other than to provide
conditional compilation, and to prevent combinatorial explosion
you must ALSO provide the ability to define aliases (recall
OpenGL has hundreds of functions in the API). So you would write:
_import "GLgetStatus": GLint -> GLint;
having preceded it by (something like)
#if _WIN32
#type GLint = int
#endif
At least now you have a Windows model. If someone wants to make
it work on Linux, Amd64, they would provide an additional branch.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net