[MLton] bool and MLton FFI

skaller skaller@users.sourceforge.net
Sat, 24 Jun 2006 13:54:39 +1000


On Fri, 2006-06-23 at 16:58 +0200, Wesley W. Terpstra wrote:

> There is some typedef for GLint; obviously, that's what you would use.
> ie: map 'typedef int GLint' to 'type GLint = C_Int.int'

Yup, that satisfies the requirement.

> > 	#if _WIN32
> > 	#type GLint = int
> > 	#endif
> 
> I'm going to assume by the above you mean something like:
> 	#ifdef X
> 	typedef int GLint;
> 	#else
> 	typedef long GLint;
> 	#endif

I mean conditional compilation of ML code reflecting the C code.
So if you have the above C code you wrote, then you need something
like:

	#if X
	type GLint = C_Int.int;
	#else
	type GLint = C_Long.long
	#endif

in the ML code, in order that the ML code be portable.

Using an FFI generator parsing the C of course can get around this,
but in general such generators don't work well enough,
and certainly don't produce portable interfaces,
at least without hinting. A generator with hints is a good 
solution IF it can be made to work well enough.

A better solution is a generator written in Perl or
Python for just that library .. for example the FFI
could be embedded in an interscript document (interscript
is my Python hosted literate programming tool, which has
extensive text generation ability because it's a superset
of Python).

However a suitable *in language* solution is much easier
to use provided it has enough semantic power.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net