Tôi đang cố gắng tìm ra cách viết hàm tùy thuộc vào một mô-đun có kiểu tham số nhưng tôi không thể tìm thấy bất kỳ thứ gì tương tự ở bất kỳ đâu. Tôi đã cố gắng giảm thiểu vấn đề càng nhiều càng tốt và kết thúc với ví dụ giả này.Tham số cục bộ tham số
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
sản lượng lỗi Error: Syntax error: module-expr expected
.
Nếu tôi rơi 'a
, tôi sẽ gặp phải lỗi sau.
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.
Cú pháp chính xác để thực hiện việc này là gì?