[英]OCaml difference between 'a option list and 'a list
I got the following results when typing this function into the OCaml toplevel. 在OCaml顶层输入此函数时,我得到以下结果。 The input appears to be identical to me both times, other that the whitespace surrounding the
::
operator. 输入似乎与我相同,除了
::
运算符周围的空白。 Can anyone explain the difference between 'a option list
and 'a option
here? 谁能解释
'a option list
'a option
和'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>
Here's what I see: 这是我看到的:
$ 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>
In my opinion, your experiment was flawed in some way. 在我看来,你的实验在某种程度上是有缺陷的。 The spacing around
::
isn't going to make any difference. 围绕
::
的间距不会有任何区别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.