11 Module Types and Signatures

OCaml has a similar feature to interfaces called signatures

Here we say "module type," because we specify what type a module has, rather than it's value. sig represents a signature. Here we specify that there must be a value called "fact," that takes an int and returns an int. It's the same type of signature that utop returns!

Here, we implement RecursiveFact which is of type Fact. The typechecker makes sure that the types are correct.

But you can have extra values!

You can have multiple modules that implement the same signature: