function - 为什么一个参数 Ocaml 函数可以使用两个参数

标签 function parameters arguments ocaml

我不明白为什么下面的函数可以使用 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/

相关文章:

c++ - 类型为 'int&' 的非常量引用的无效初始化,原因是什么?

c - 这些 C 函数签名与我以前看到的不同。这些是做什么的,为什么这样写?

function - MATLAB 函数中的可选参数

function - OCaml - 给出类型为 (int -> int) -> int 的函数

c - 使用 c 中函数的 int 值定义 arraysize

python - 指定函数中的输入类型

c++ - 同时进行优化和可测试性——如何将代码分解成更小的单元

c++ - 什么可能导致 `MyType *pType` 在返回时从有效参数变为 null?

arrays - 如何将查询与数组一起使用

c++ - g++ vs intel/clang 参数传递顺序?