结构内部的签名

发布于 2024-08-06 15:37:24 字数 405 浏览 12 评论 0原文

我想将签名/结构对放置在结构内部,如下所示:

structure Outer :> OUTER =
struct
    signature INNER =
    sig
        ...
    end

    structure Inner :> INNER =
    struct
    ...
    end
end

但即使是最简单的示例也会产生错误:

../test.sml:1.18-2.6 Error: syntax error: replacing  STRUCT with  EQUALOP
../test.sml:5.6 Error: syntax error found at END

看来结构内部不允许签名。实现此功能的最佳方法是什么?

I want to place signature/structure pair inside a structure, like so:

structure Outer :> OUTER =
struct
    signature INNER =
    sig
        ...
    end

    structure Inner :> INNER =
    struct
    ...
    end
end

but even the simplest of examples produces an error:

../test.sml:1.18-2.6 Error: syntax error: replacing  STRUCT with  EQUALOP
../test.sml:5.6 Error: syntax error found at END

It appears that signatures are not allowed inside structures. What is the best way to achieve this functionality?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狂之美人 2024-08-13 15:37:24

尽管结构嵌套在 SML 中,但签名却不然。目前尚不清楚您想要实现什么功能:

  • 隐藏命名签名是不可能的。

  • 使INNER签名依赖于结构Outer中声明的类型是通过fibration实现的(where type条款)。在 Benjamin Pierce 的关于编程语言高级类型的书中,Harper 和 Pierce 的教程中有一个关于纤维化的详细部分。

Although structures nest in SML, signatures do not. It's not clear what functionality you want to achieve:

  • Hiding a named signature is impossible.

  • Having the INNER signature depend on types declared in structure Outer is achieved through fibration (the where type clause). There's a length section on fibration in the tutorial by Harper and Pierce in Benjamin Pierce's book on advanced types in programming languages.

如梦初醒的夏天 2024-08-13 15:37:24

您还可以内联内部签名,如

structure Outer :> OUTER =
struct
    structure Inner :> sig
      ...
    end
      =
    struct
    ...
    end
end

You could also inline the inner signature, as in

structure Outer :> OUTER =
struct
    structure Inner :> sig
      ...
    end
      =
    struct
    ...
    end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文