将此功能输入OCaml顶级时,我得到以下结果。输入似乎与我相同,除了::
运算符周围的空白。任何人都可以在这里解释'a option list
和'a option
之间的区别吗?
# let rec at i = function
| [] -> None
| h::t -> if i = 1 then Some h else at (i-1) t;;
val at : int -> 'a option list -> 'a option = <fun>
# let rec at i = function
| [] -> None
| h :: t -> if i = 1 then Some h else at (i-1) t;;
val at : int -> 'a list -> 'a option = <fun>
答案 0 :(得分:3)
这就是我所看到的:
$ ocaml
OCaml version 4.01.0
# let rec at i = function
| [] -> None
| h::t -> if i = 1 then Some h else at (i-1) t;;
val at : int -> 'a list -> 'a option = <fun>
# let rec at i = function
| [] -> None
| h :: t -> if i = 1 then Some h else at (i-1) t;;
val at : int -> 'a list -> 'a option = <fun>
在我看来,你的实验在某种程度上存在缺陷。 ::
周围的间距不会产生任何影响。