Опитвам се да разбера как да напиша функция в зависимост от модул с параметричен тип, но не мога да намеря нищо подобно никъде. Опитах се да намаля проблема колкото е възможно повече и завърших с този фиктивен пример.
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
което дава грешка Error: Syntax error: module-expr expected
.
Ако изпусна 'a
, ще получа следната грешка.
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.
Какъв е правилният синтаксис за това?