I am new to OCaml and I am struggling a bit with understanding how module types work.
module type I = sig
type t
end
module EQ (M : I) = struct
let equal (x : M.t) (y : M.t) = x = y
end
(* Explicitly type declaration *)
module A : I = struct
type t = string
end
module EStr1 = EQ (A)
(* Error: This expression has type string but an expression was expected of type
A.t *)
let _ = EStr1.equal "1" "0" |> string_of_bool |> print_endline
(* No type declaration *)
module B = struct
type t = string
end
module EStr2 = EQ (B)
(* OK. Outputs false *)
let _ = EStr2.equal "1" "0" |> string_of_bool |> print_endline
In the code above i declared module type I, module A with explicit module type declaration and module B without module type declaration. EQ is functor that receives module of type I and returns module with equal method.
Example with module A result in compiling error, while another works as I expected. What is semantic difference between this examples?