In an attemp to write a map
function over Bigarray.Genarray
with the following signature :
val map : ('a -> 'b) -> ('a,'c,'d) Genarray.t -> ('b, 'c, 'd) Genarray.t
I ended up with the following implementation :
let map f a =
let dims = Genarray.dims a in
let map_a2b i = f (Genarray.get a i) in
Genarray.init (Genarray.kind a) (Genarray.layout a) dims map_a2b
(* ^^^^^^^^^^^^^^^
wrong
*)
which is not correct since Genarray.kind a
will give the kind of elements of the array a
whereas I am here looking for the kind of the image of array a
’s elements by the map f
.
How can I do that, if only it is possible ? Am I forced to pass it as an argument to the map
function ?