Search code examples
smlsmlnj

why do some functions in the List structure require the "List" prefix and some do not?


(I am using SML/NJ)

The list structure http://sml-family.org/Basis/list.html includes @, hd, tl, null, concat, etc.

Some of them are available without a prefix: @, hd, tl, [], concat. But others, such as exists, and nth require the List prefix. see below:

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

Why? I tried to find an answer in the "Definition of Standard ML (1997)" but I could not find anything related to this.


Solution

  • Some names are available unqualified because they are also bound in the top-level environment of the SML Basis library, including the ones you listed. See here for a complete list.