为什么 `a:: nil` 中的 `a` 代表长度为 1 的列表?
Why does `a` in `a :: nil` represent a list of length 1?
在 Ullman 的 SML 书中:
Note that the way we express "list of length 1" as a pattern is to put
square brackets around a single identifier, like [a]
.
Such a pattern can only match a list with a single element, and variable a
acquires that element as its value.
Another way to express "list of length 1" is with the pattern a :: nil
.
Again, a
acquires the lone element as its value.
在a :: nil
中,a
是否表示列表的头元素?为什么表示长度为1的列表?
谢谢。
a
是列表的头部,nil
是列表的尾部。 nil
是一个长度为零的列表,因此 a :: nil
的长度为 1。
在 Ullman 的 SML 书中:
Note that the way we express "list of length 1" as a pattern is to put square brackets around a single identifier, like
[a]
. Such a pattern can only match a list with a single element, and variable a acquires that element as its value.Another way to express "list of length 1" is with the pattern
a :: nil
. Again,a
acquires the lone element as its value.
在a :: nil
中,a
是否表示列表的头元素?为什么表示长度为1的列表?
谢谢。
a
是列表的头部,nil
是列表的尾部。 nil
是一个长度为零的列表,因此 a :: nil
的长度为 1。