我不明白为什么下面的函数可以使用 2 个参数,即使我们用一个参数声明它:
let rec removeFromList e = function
h :: t -> if h=e then h
else h :: removeFromList e t
| _ -> [];;
removeFromList 1 [1;2;3];;
最佳答案
您使用两个参数来声明它。语法:
let f = function ...
可以看作是
的快捷方式let f x = match x with
所以,你的定义实际上是:
let rec removeFromList e lst = match lst with
h :: t -> if h=e then h else h :: removeFromList e
关于function - 为什么一个参数 Ocaml 函数可以使用两个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37545526/