小编Joo*_*sie的帖子

有人可以像我五岁一样解释 OCaml 尾递归吗?

我无法将我的大脑围绕尾递归,特别是在 ocaml 中,也解释了为什么人们在最后调用“in”函数。PS我说的是最基本的尾递归函数。

ocaml

2
推荐指数
1
解决办法
747
查看次数

如何将常规列表变成选项列表

let rec some_none list =
  match list with
  | [] -> list
  | hd::tl -> 
      if hd = 0 then 
        [None] @ some_none tl 
      else
        [Some hd] @ some_none tl;;                                      
Run Code Online (Sandbox Code Playgroud)

当我运行这个程序时它返回

Error: This expression has type int list but an expression was expected of type
     'a option list
   Type int is not compatible with type 'a option 
Run Code Online (Sandbox Code Playgroud)

我怎样才能将常规更改a' lista' option list

ocaml

0
推荐指数
1
解决办法
343
查看次数

标签 统计

ocaml ×2