I’m new to OCaml, and working on a basic app to learn incr_dom, and when I try to use List.map to turn a list of strings into things that I can put into the DOM, I get the following error:
File "bin/app.ml", line 100, characters 26-35:
100 | List.map ~f:view_spot m.spot_items;
^^^^^^^^^
Error: The function applied to this argument has type
?key:Base.string -> Virtual_dom__Node.t
This argument cannot be applied with label ~f
view_spot should have type string -> node_creator, and doing replacing that line with [view_spot "some string"]; works as expected. That said, using any sort of map, even a self-defined one, seems to result in that error.
Looking in the documentation, apparently node_creator is the same as ?key:Base.string -> ?attrs:Virtual_dom__.Attr.t Base.list -> t Base.list -> t, which seems to be where the issue is coming from. That said, I’m not sure how to work around this or why exactly this is an issue.
This argument cannot be applied with label ~f
This error is telling you that the label on the argument is unexpected, so I’m guessing in this context
List.map view_spot m.spot_items;
will work for you.
Are you trying to use List from Base or the OCaml Stdlib?
Base extensively uses labelled arguments while they are more rare on the Stdlib. If you intended to use Base (and it’s correctly installed and your build system is configured to use it) then you need to start your file with
open Base
to make sure you are using it instead of the Stdlib.
I do have open Base at the top, but I get the same error even if I use Stdlib.List.map view_spot m.spot_items; (with out the ~f:). If I get rid of the ~f: with how it currently is, I get the following error:
File "bin/app.ml", line 100, characters 23-32:
100 | List.map view_spot m.spot_items;
^^^^^^^^^
Error: The function applied to this argument has type
?key:Base.string -> Virtual_dom__Node.t
This argument cannot be applied without label
So in one case I have an argument that cannot be applied with a label, and in the other I have an argument that cannot be applied without a label. Literally the only difference between the error messages is that the second one has “out” at the end of “with” .
I’m pretty sure that the first code I posted is more correct, again because I do have open Base at the top so using the ~f convention is probably right, but I’m still not really sure what’s going on.
You need to put parentheses around List.map ~f:view_spot m.spot_items. As it stands, the compiler sees List.map as the second argument to Node.tbody, ~f:view_spot as the third argument, and so on.