【发布时间】:2015-09-22 05:55:46
【问题描述】:
所以我有这个练习:
filter (fun x -> x = 0) [(1,0);(2,1);(3,0);(4,1)];;
result int list [1;3]
所以基本上你必须将你的 x in fun 与列表中的第二个数字相匹配,如果相同,则使用第一个数字创建新列表。
我的解决方法是错误的
let rec filter f = function
| []->[]
| x::l -> if f=snd x then fst x :: filter f l else [];;
当我想尝试代码时出现以下错误:
错误:此表达式的类型为
int,但预期的表达式为 类型int -> bool
【问题讨论】:
标签: list function types filter ocaml