I have already defined an interface and a module:
module type BASE =
sig
type 'a base
val ...
...
end
module base =
(struct
type 'a base
let ...
...
end: BASE)
I would like to define another interface DERIVED inherited from BASE, which includes all the types and signatures of BASE, and has its own types and declarations. Then I could define another module Derived whose type is DERIVED.
Could anyone tell me how to do it? Is it necessarily the object feature of OCaml?
Going further, is it possible to change the names of the types of DERIVED: for instance, it is called 'a derived instead of ‘a base?
You can use
includeon both signature and implementations.This is a simple inclusion of structure. It is not “(implementation) inheritance” in the sense of OOP, because there is no late-binding (open recursion) involved. If you define a value
finDerivedthat was previously defined inBase, it will shadow the previousf, but call toffromBasewill still use the old value, not the new implementation.