Próbuję dowiedzieć się, jak napisać funkcję w zależności od modułu z parametrowym typem, ale nie mogę znaleźć niczego podobnego w dowolnym miejscu. Starałem się maksymalnie ograniczyć problem i skończyłem z tym fałszywym przykładem.Parametrycznie lokalnie abstrakcyjny typ
module type Mappable = sig
type 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
end
let plus (type m) (module M : Mappable with type 'a t = 'a m) (xs : int m) =
M.map (fun x -> x + 1) xs
która podaje błąd Error: Syntax error: module-expr expected
.
Jeśli upuszczę 'a
, otrzymam następujący błąd.
Error: In this `with' constraint, the new definition of t
does not match its original definition in the constrained signature:
Type declarations do not match: type t is not included in type 'a t
They have different arities.
Jaka jest prawidłowa składnia w tym celu?