Using Poly/ML to build projects with nested directory structures

纵饮孤独 提交于 2019-12-23 01:38:28

问题


Until now, I have been using Poly/ML for several small projects where all source code files are all in the same directory. To build these projects, all I had to do was run the following command in the REPL:

> PolyML.make "Main";

But now I have a project whose scale makes it impractical to put all source code files in the same directory. To build these projects in the REPL, I need to run the following commands:

> PolyML.make "foo/Foo";
> PolyML.make "bar/Bar";
> PolyML.make "qux/Qux";
> PolyML.make "Main";

which is not terribly practical as the number of subsystems grows.

Is there any way to automate the process of building projects with nested directory structures in Poly/ML?


P.D.: I have had a look at both SML/NJ's Compilation Manager and MLton's ML Basis system. While unquestionably powerful, these are too complicated for my needs.


回答1:


Put a file called ml_bind.ML in each of the sub-directories and have those files build the component for that directory.

PolyML.make expects the name of the source file to match the name of the component (structure, signature or functor). So if it is looking for a structure called "Foo" it will expect the source for "Foo" in a file called "Foo", "Foo.ML" or "Foo.sml". If instead it finds a directory called "Foo" it recursively enters the "Foo" directory and uses the "ml_bind.ML" file as the guide to build the "Foo" structure. Typically, "Foo/ml_bind.ML" will look like

structure Foo = FooFunctor(structure A = FooA and B = FooB);

with files "Foo/FooFunctor.ML", "Foo/FooA.ML" and "Foo/FooB.ML" containing the source for "FooFunctor", "FooA" and "FooB" respectively.

You can find examples of this in the code for the Poly/ML compiler which comes as part of the Poly/ML source code distribution.




回答2:


You could have a build.sml file listing and use-ing all project files:

use "bar/bar.sml";
use "foo/foo.sml";
use "main.sml";

Or, a little bit more concise:

app use [
  "foo/foo.sml",
  "bar/bar.sml",
  "main.sml"
]

Where app is the standard List.app.

Then you can build just this one file:

$ polyc -o main main.sml
$ # or
$ poly
> PolyML.make "build.sml"


来源:https://stackoverflow.com/questions/29315827/using-poly-ml-to-build-projects-with-nested-directory-structures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!