[MLton] can mlbasis rename the top-level?
Matthew Fluet
fluet@cs.cornell.edu
Tue, 6 Sep 2005 13:44:40 -0400 (EDT)
> Using the MLB files to rename structures is very useful.
> However, what about things at the top-level?
Structures are at the top-level. But, no, there is no means to rename
Core language bindings at the tope-level. You can always drop down into a
.sml file to do so. Likewise, you can't open a structure in an MLB file,
you need to drop down to .sml.
At this point, Stephen usually chimes in and says how useful it would be
allow raw SML in a MLB file, with the obvious semantics. And, I'm
becoming more and more convinced of the utility of this. I think some
sort of "escape" mechanism, like in MLYacc for dentoting semantic actions
or "here documents" in bash, would be useful:
local
$(SML_LIB)/basis/basis.mlb
$(SML_LIB)/smlnj-lib/Util/smlnj-lib.mlb
in
{{{
structure IntRedBlackMap = RedBlackMapFn(type ord_key = int
val compare = Int.compare)
}}}
end
I like the idea of delimiting the the sml in a manner that doesn't require
embedding the SML grammar in the MLB grammar. I imagine something like
the above could be handled by the lexer, yielding a (big) string token,
which could be pushed through the SML lexer/parser rather than a file
name.
> If a library exports '$' at the top-level, can I move it?
> I mean something like:
>
> local
> libdemo.mlb (* exports $ at the top-level *)
> in
> structure Demo = *
> mycode.sml (* expects $ placed in Demo.$ *)
> end
>
> I want all of the top-level stuff defined in libdemo.mlb put
> inside a single structure, out of my top-level namespace.
Bear in mind, that the top-level basis includes type, value (including
datatype constructors and exception constructors), structures, signatures,
and functors. Signatures and functors may not be reified into a
structure. So, it is a bit more complicated to extract the portion of the
basis that is acceptable in a signature.
> This is the sort of problem I thought MLB files solve, but I
> can't figure out how to do this from the documentation.
It isn't possible with the syntax and semantics currently available. And,
I'm not convinced that you shouldn't be doing:
local
local
libdemob.mlb
in
mydemo.sml
end
in
mycode.sml
end
where mydemo.sml explicitly rebinds the portion of libdemob.mlb that you
wish available through structure Demo.