Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 645

Module type semantics in OCaml

$
0
0

I am new to OCaml and I am struggling a bit with understanding how module types work.

module type I = sig  type tendmodule EQ (M : I) = struct  let equal (x : M.t) (y : M.t) = x = yend(* Explicitly type declaration *)module A : I = struct  type t = stringendmodule 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 = stringendmodule 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 recieves module of type I and returns module with equal method.Example with module A result in compiling error, while other works as i expected. What is semantic difference between this examples?


Viewing all articles
Browse latest Browse all 645

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>