为什么一个参数 Ocaml 函数使用两个参数

Why one parameter Ocaml function works with two arguments

我无法理解为什么即使我们用一个参数声明以下函数也可以使用两个参数:

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