gpt4 book ai didi

sml - 如何编译多个SML文件?

转载 作者:行者123 更新时间:2023-12-01 09:21:53 25 4
gpt4 key购买 nike

在 Standard-ML 中编译多个文件是如何工作的?我有 2 个文件。

file1.sml:

(* file1.sml *)
datatype fruit = Orange | Apple | None

file2.sml:

(* file2.sml *)
datatype composite = Null | Some of fruit

如您所见,file2.sml 使用了 file1.sml 中的内容。我怎样才能编译这个东西?

我正在使用 mosmlc.exe 并且在编译 mosmlc file2.sml 时(对于 this question ):

(* file2.sml *)
use "file1.sml";
datatype composite = Null | Some of fruit

我得到:

! use "file1.sml";
! ^^^
! Syntax error.

那么,如何处理多个文件呢?

最佳答案

您可以在 Moscow ML Owner’s Manual 中阅读更多内容,但在您的特定情况下,以下命令甚至无需在源代码中使用 use 即可工作:

mosmlc -toplevel file1.sml file2.sml

使用结构模式

当你想将你的代码组织成结构时,你可以使用mosmlc-structure标志。例如,给定以下文件:

你好.sml

structure Hello =
struct
val hello = "Hello"
end

世界.sml

structure World =
struct
structure H = Hello

val world = H.hello ^ ", World!"
end

主.sml

fun main () =
print (World.world ^ "\n")

val _ = main ()

您现在可以获得一个名为 main 的可执行文件,如下所示:

mosmlc -structure Hello.sml World.sml -toplevel main.sml -o main

然后运行它:

$ ./main
Hello, World!

结构模式要求文件的名称和包含的结构一致,就像在 Java 中类和文件必须具有相同的名称一样。您还可以使用包含签名的 .sig 文件。

关于sml - 如何编译多个SML文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36947466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com