在管给出的骨架,它使用List.fold_left得到一个OCaml的功能填写 val pipe : ('a -> 'a) list -> ('a -> 'a)
这样pipe [f1;...;fn]
(其中f1,...,fn
的功能!)返回一个函数f
这样,对于任何x
,我们有f x
返回结果fn(...(f2(f1 x)))
。ocaml的函数调用List.fold_left
同样,您的任务是为折叠功能f
和基本情况填写适当的值。 一旦你已经实现的功能,你应该在OCaml的提示得到以下行为:
# pipe [] 3;;
- : int = 3
# pipe [(fun x -> x+x); (fun x -> x + 3)] 3 ;;
- : int = 9
# pipe [(fun x -> x + 3);(fun x-> x + x)] 3;;
- : int = 12
以下是你需要填写代码:
let pipe fs =
let f a x = failwith "to be implemented" in
let base = failwith "to be implemented" in
List.fold_left f base fs
有人可以帮助我?
我认为通常的作业规则是你应该显示一些你已经尝试过的代码。没有什么可以评论的,没有解决问题就很难提供帮助。 – jrouquie
以及我认为它的基地应该让基地= 0,但我不知道f部分。我将如何做到这一点。 –