I defined the vector GADT as the following:
module Vector = struct
type ('a, 'size) t =
| [] : ('a, z) t
| (::) : 'a * ('a, 'size) t ->
('a, 'size s) t
end
I tried implementing map like the following:
let rec map (type size num_elem_to_add) ~(f:'a -> 'b) (vector: ('a, size) t) : ('b, size) t =
match vector with
| x::xs -> f x :: map ~f vector
| [] -> []
However, I am getting the compiling error:
This expression has type 'a but an expression was expected of type ('b, $0) t
The type constructor $0 would escape its scope
How would I be able to fix this?