【发布时间】:2010-12-12 15:21:31
【问题描述】:
我想要一个List.map 的尾递归版本,所以我自己写了一个。这里是:
let rec list_map f l ?(accum=[])=
match l with
head :: tail -> list_map f tail ~accum:(head :: accum)
| [] -> accum;;
每当我编译这个函数时,我都会得到:
File "main.ml", line 69, characters 29-31:
Warning X: this optional argument cannot be erased.
tutorial 表示这意味着我正在尝试创建一个没有非可选参数的函数。但是上面的函数显然需要非可选参数。
我可能只是在做一些非常愚蠢的事情,但是什么?
【问题讨论】:
-
你应该看看 ocaml 邮件列表上关于尾递归映射的最新帖子。 groups.google.com/group/fa.caml/browse_thread/thread/…
标签: ocaml compiler-warnings optional-arguments