2

我目前正在标准 ML 中构建一个测试库(使用 Poly/ML 作为解释器)。我有以下目录结构:

project/a.sml
project/src/b.sml
project/src/c.sml
...

哪里a.sml只是一堆调用使用

use "src/b.sml"
use "src/c.sml"
...

b.smlc.sml都是这样的结构定义

structure ComponentX
struct
...
end

它形成了库中很好的、逻辑分离的组件。我有时也会在一个文件中创建一个模块,然后在另一个文件中的同一模块中引入一个子结构。

然后我可以在项目的根目录中正常使用测试库,方法是调用use "a.sml".

但是,我似乎无法在其自己的目录之外使用代码,这有点问题。例如,假设我在project. 如果我然后调用use "project/a.sml",则后续调用会use "src/x.sml"尝试src在父级中查找目录(该目录不存在)。

有什么方法可以做一个 relative use,还是有更好的方法来完全构建它?

4

1 回答 1

4

The use function itself in Poly/ML doesn't change the path when it is used recursively. You will need to change the path within the sub-directory explicitly using OS.FileSys.chDir. use is just a function so you could redefine it if you wanted. The OS.Path and OS.FileSys structures could be useful.

An alternative is to reorganise your code to make use of PolyML.make. You would have to rename your files to match the name of the structure that each file contains e.g. ComponentX.sml would contain structure ComponentX. For more on this see polyml.org/documentation/Reference/PolyMLMake.html or a this answer about Poly/ML with nested directory structures.

于 2015-05-24T12:50:20.567 回答