OCaml sub-module limited to sub-record

I have a Mod module that is limited to a Sig signature. The module has a Nested submodule. The signature has a Nested subcategory:

 module type Sig = sig val a : int module type Nested = sig val b : int end end module Mod : Sig = struct let a = 1 module Nested = struct let b = 2 end end 

However, this gives the following error:

 Error: Signature mismatch: Modules do not match: sig val a : int module Nested : sig val b : int end end is not included in Sig The field `Nested' is required but not provided 

What am I missing?

+4
source share
1 answer

The way to declare a nested module was incorrect in your code:

 module type Sig = sig val a : int module Nested : sig val b : int end end module Mod : Sig = struct let a = 1 module Nested = struct let b = 2 end end 

See how submodules are declared at the following link: http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora131.html

It helps me fix your mistake.

+7
source

All Articles