OCaml - 实现嵌套函数
OCaml - Implement nested functions
我想实现递归的嵌套函数。怎么做?
我在以下代码中遇到错误 "an operator expected"
let powerset_cf f1 = if (let rec f lst = match lst with
[] -> true
| h::t -> if (f1 h) then (f t)
else false ) then true
else false;;
在这里,
lst = 任何列表(例如 [1;2;3])
f1 任何特征函数,如果元素在特征函数定义的集合中,则 returns 为真。 (例如让 f1 x = (x mod 3 == 0 && x<=15);; )
powerset_cf 函数 returns 如果 lst 是特征函数幂集的成员,则为真。
请帮忙解决这个问题。提前致谢。
let powerset_cf f1 lst =
let rec f lst =
match lst with
| [] -> true
| h::t -> if f1 h then f t else false
in
if f lst then true else false
;;
当然我们可以简化代码,但这不是问题。
我想实现递归的嵌套函数。怎么做? 我在以下代码中遇到错误 "an operator expected"
let powerset_cf f1 = if (let rec f lst = match lst with
[] -> true
| h::t -> if (f1 h) then (f t)
else false ) then true
else false;;
在这里, lst = 任何列表(例如 [1;2;3]) f1 任何特征函数,如果元素在特征函数定义的集合中,则 returns 为真。 (例如让 f1 x = (x mod 3 == 0 && x<=15);; ) powerset_cf 函数 returns 如果 lst 是特征函数幂集的成员,则为真。
请帮忙解决这个问题。提前致谢。
let powerset_cf f1 lst =
let rec f lst =
match lst with
| [] -> true
| h::t -> if f1 h then f t else false
in
if f lst then true else false
;;
当然我们可以简化代码,但这不是问题。