The following has been tried on js_of_ocaml 3.5.1 and 3.5.2.
I’m trying to transform a js_array from an 'a
to a 'b
however I’m getting errors which suggest that map can only transform an 'a
to an 'a
. The interface states the type is:
method map : ('a -> int -> 'a js_array t -> 'b) callback -> 'b js_array t meth
The important part being:
('a -> int -> 'a js_array t -> 'b) callback
But the top level gives me:
#show Js_of_ocaml.Js.js_array;;
method map :
('a -> int -> 'a Js_of_ocaml.Js.js_array Js_of_ocaml.Js.t -> 'a)
Js_of_ocaml.Js.callback ->
'a Js_of_ocaml.Js.js_array Js_of_ocaml.Js.t Js_of_ocaml.Js.meth
The important part being:
('a -> int -> 'a Js_of_ocaml.Js.js_array Js_of_ocaml.Js.t -> 'a) Js_of_ocaml.Js.callback
And just to try it:
open Js_of_ocaml;;
let arr = Js.array [| 1; 2; 3 |];;
val arr : int Js_of_ocaml.Js.js_array Js_of_ocaml.Js.t = <abstr>
arr##map (Js.wrap_callback (fun v _ _ -> float v));;
Line 1, characters 0-8:
Error: This expression has type
(int -> int -> int Js_of_ocaml.Js.js_array Js_of_ocaml.Js.t -> int)
Js_of_ocaml.Js.callback ->
int Js_of_ocaml.Js.js_array Js_of_ocaml.Js.t Js_of_ocaml.Js.meth
but an expression was expected of type
(unit,
int -> int -> int Js_of_ocaml.Js.js_array Js_of_ocaml.Js.t -> float)
Js_of_ocaml.Js.meth_callback -> 'res Js_of_ocaml.Js.meth
Type
(int -> int -> int Js_of_ocaml.Js.js_array Js_of_ocaml.Js.t -> int)
Js_of_ocaml.Js.callback =
(unit,
int -> int -> int Js_of_ocaml.Js.js_array Js_of_ocaml.Js.t -> int)
Js_of_ocaml.Js.meth_callback
is not compatible with type
(unit,
int -> int -> int Js_of_ocaml.Js.js_array Js_of_ocaml.Js.t -> float)
Js_of_ocaml.Js.meth_callback
Type int is not compatible with type float
What’s going on here? Is there a way to use map
?