为什么List结构中的某些函数需要“List”前缀而有些函数不需要?

问题描述 投票:2回答:1

(我使用的是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个回答
3
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.