5
votes

I'm working on a relatively large SML codebase. It was originally written to compile with MLton, but I'm now working with it under SML/NJ. I need to use RedBlackMapFn, which is defined in smlnj-lib.cm. However, I get an error:

elaborate/elaborate-bomenv.fun:9.20-9.27 Error: unbound signature: ORD_KEY
elaborate/elaborate-bomenv.fun:14.21-14.40 Error: unbound functor: RedBlackMapFn
elaborate/elaborate-bomenv.fun:32.20-32.27 Error: unbound signature: ORD_KEY
elaborate/elaborate-bomenv.fun:37.21-37.40 Error: unbound functor: RedBlackMapFn

So I assume that smlnj-lib.cm is not being pulled by CM. In an effort to fix this, I added $/smlnj-lib.cm to the sources.cm file in the directory that I'm working in. This causes a separate issue:

elaborate/sources.cm:25.1-25.18 Error: structure Random imported from $SMLNJ-LIB/Util/smlnj-lib.cm@243997(random.sml) and also from ./(sources.cm):lib/(sources.cm):basic/(sources.cm):random.sml
elaborate/sources.cm:25.1-25.18 Error: structure Queue imported from $SMLNJ-LIB/Util/smlnj-lib.cm@436143(queue.sml) and also from ./(sources.cm):lib/(sources.cm):basic/(sources.cm):two-list-queue.sml

No dice. I tried removing the Random structure that's coming from ./(sources.cm):lib/(sources.cm):basic/(sources.cm):random.sml, but it appears that it isn't equivalent to the one defined in the standard library, so I can't just substitute one for the other.

I'd like to use something like Python's import ... from ... as ... mechanism to give a new name to the Random that's coming from the standard library, but CM's documentation doesn't offer any hints as to how I'd go about that.

How can I resolve a module naming conflict across multiple SML files?

1
@newacct Not true, it looks like CM doesn't pull in $/smlnj-lib.cm if it would cause a naming conflict (like it is for me). I can get at RedBlackMapFn in other SML code that I've written, but not in this project.Patrick Collins
Maybe a function that wraps RedBlackMapFn in a separately compiled module implementing a signature that hides the second declaration of random? Disclaimer: There's a reason this is a comment and not an answer.ben rudgers
@benrudgers I ended up splitting the file that needed RedBlackMapFn off into a separate .cm file and that worked. It's kind of ugly though. It would be nice to know if there's a better way.Patrick Collins
Glad you got it working. Have you considered posting it as an answer?ben rudgers
@benrudgers I was hoping someone else had a better idea, but sure, I'll post it now.Patrick Collins

1 Answers

3
votes

I ended up splitting off the problematic file in to a separate .cm. The problem file here is elaborate-bomenv.{sig, fun}. The .cm file for this directory is sources.cm, which caused errors when it looked like:

Group
...
is

$/basis.cm
...
elaborate-bomenv.fun
elaborate-bomenv.sig
...

So instead, I made an elaborate-bomenv-sources.cm that looks like:

Group

signature ELABORATE_BOMENV
functor BOMEnv

is

$/smlnj-lib.cm
...
elaborate-bomenv.sig
elaborate-bomenv.fun

and changed the original sources.cm to read:

Group
...
is

$/basis.cm
...
./elaborate-bomenv-sources.cm
...

Which is ugly, but it works.