【问题标题】:why do some functions in the List structure require the "List" prefix and some do not?为什么 List 结构中的某些函数需要“List”前缀而有些则不需要?
【发布时间】:2018-09-19 14:41:27
【问题描述】:

(我使用的是 SML/NJ)

列表结构http://sml-family.org/Basis/list.html包括 @、hd、tl、null、concat 等

其中一些可以不带前缀:@、hd、tl、[]、concat。 但是其他的,例如 exists 和 nth 需要 List 前缀。见下文:

Standard ML of New Jersey v110.79 [built: Tue Aug  8 23:21:20 2017]
- op @;
val it = fn : 'a list * 'a list -> 'a list
- concat;
val it = fn : string list -> string
- nth;
stdIn:3.1-3.4 Error: unbound variable or constructor: nth
- exists;
stdIn:1.2-2.1 Error: unbound variable or constructor: exists
- List.nth;
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable]
[autoloading done]
val it = fn : 'a list * int -> 'a
- List.exists;
val it = fn : ('a -> bool) -> 'a list -> bool

为什么?我试图在“标准 ML 的定义(1997)”中找到答案 但我找不到与此相关的任何内容。

【问题讨论】:

    标签: sml smlnj


    【解决方案1】:

    有些名称是不合格的,因为它们也绑定在 SML Basis 库的顶级环境中,包括您列出的那些。有关完整列表,请参阅 here

    【讨论】:

    • 我不明白这如何真正回答“为什么?”这个问题。 OP 已经知道一些列表函数可以以不合格的方式使用,而有些则没有。您的“因为”可能涉及 如何 它是完成的,而不是 为什么 它是完成的。
    • @JohnColeman,由于 OP 提到他已经在语言定义中寻找答案,我假设他的“为什么”将被解释为“为什么这个工作”,如:哪里是它指定了。但也许他可以澄清一下。 (无聊的理由只是为最常见的情况提供便利。)
    • 我明白你的意思。您提供的链接明确解决了“为什么”问题。我将其解释为为什么该语言的设计方式使得某些列表函数可以直接使用,但有些需要在列表结构中使用。
    猜你喜欢
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 2014-03-19
    • 2016-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多