我在OCaml工作,使用的环境是Eclipe Mars。当我尝试使用List.iter [1.;3.;2.;-7.;4.;5.] ~f:(fun x -> update rsum x);;它时,出现了一个错误,提示Error: The function applied to this argument has type 'a list -> unit
This argument cannot be applied with label ~f#
意思是这是一本书的例子,可以很好地为他们服务,但是当我尝试使用时,我经常遇到这个错误~f:。有人可以解释一下为什么这行不通吗?如果我知道如何进行这项工作,那也会有所帮助。
我有一个问题,为什么OCaml表现得有点不寻常.通过定义功能
let abs_diff x y = abs(x - y);;
我们val abs_diff : int -> int -> int = <fun>现在通过定义为
let abs_diff x y =
fun x -> (fun y -> abs(x - y));;
val abs_diff : 'a -> 'b -> int -> int -> int = <fun>
现在使用另一个名为as的函数
let dist_from3 = abs_diff 3;;
第一个定义它完美地工作但是第二个定义它没有按预期工作.我们明白了
val dist_from3 : '_a -> int -> int -> int = <fun>
为什么它表现得那样,为什么这两个定义看起来相同的功能不同?