Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

label ~f in OCaml

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.

like image 812
measuretheory Avatar asked Mar 13 '23 08:03

measuretheory


1 Answers

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.

like image 78
Kakadu Avatar answered Mar 20 '23 22:03

Kakadu