[MLton] MLton import headers

Matthew Fluet fluet at tti-c.org
Sat Oct 4 07:50:19 PDT 2008


On Sat, 4 Oct 2008, Wesley W. Terpstra wrote:
> On Fri, Oct 3, 2008 at 10:21 PM, Matthew Fluet <fluet at tti-c.org> wrote:
>> Things seem
>> sufficiently complex that it is unclear whether a complicated set of
>> implicit defaults is enough to shield a programmer completely (or even
>> mostly) from the details of which they need to be aware.  If that is the
>> case, then it is often simpler to allow/force someone to be explicit up
>> front, since that may be easier than trying to back out of the implicit
>> defaults when the need arises.
>
> So you would propose that I always require the user to
> #define PART_OF_X / STATIC_LINK_X / DYNAMIC_LINK_X before #include'ing
> the header?

Not necessarily.  What is 'best/common' practice?  Doing a
'grep -r "(visibility(" /usr/include/*' (on an x86-linux) turns up some 
headers that use it, but none appear to demand a
#define PART_OF/STATIC_LINK/DYNAMIC_LINK in order to control the 
visibility.

>> ---foo_import.src---
>> structure Foo = struct
>>  val libopen = _import "foo_open" FOO_SCOPE: int * string vector -> unit;
>>  val libclose = _import "foo_close" FOO_SCOPE: unit -> unit;
>> end
>> ------
>> ---Makefile---
>> FOO_SCOPE=public
>>
>> foo_import.sml: foo_import_src
>>        sed 's|FOO_SCOPE|$(FOO_SCOPE)|' < foo_import.scc > foo_import.sml
>
> Well, I thought it would be nicer to have
> structure FooStatic = struct
> val libopen = _import "foo_open" public: int * string vector -> unit;
> val libclose = _import "foo_close" public: unit -> unit;
> end
> structure FooDynamic = struct
> val libopen = _import "foo_open" public: int * string vector -> unit;
> val libclose = _import "foo_close" public: unit -> unit;
> end
> structure Foo = FooStatic (* or whatever a sane default is *)
>
> ... my way you can use functors and/or the basis system to do what you
> want without having to drop out to make.

I don't see how functors and/or the ml basis sytem help here.  Neither 
allow for control-flow or conditional compilation.  In your example above, 
there is no way to change Foo from FooStatic to FooDynamic without 
changing the source file.  As Vesa noted, you can use MLB variables to get 
a poor-man's form of conditional compilation, but then you have to (in the 
Makefile) load an appropriate mlb-path-map.




More information about the MLton mailing list