I am working in OCaml, the environment that I use is Eclipe Mars. And when I try using List.iter [1.;3.;2.;-7.;4.;5.] ~f:(fun x -> update rsum x);;
it gives an error saying that Error: The function applied to this argument has type 'a list -> unit
This argument cannot be applied with label ~f#
The point is that this is an example from a book which works for them perfectly but I constantly get this error when I try to use ~f:
. Can somebody explain me why this does not work?
And also it would help if I knew how to make this work.
The tilde introduces the feature known as labelled argument. OCaml standard library has module List where functions are declared without labelled arguments and module ListLabels which uses them.
My hypothesis is that you are reading Real World OCaml when authors use another standard
library called Core
. This library has it's own List module and this library uses labelled arguments a lot. So, you probably forgot to load this library into toplevel. You probably need to explain Eclispe how to load right library or write module List=ListLabels
at top of your source file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With