(* Attempt 1: Does not work, because type not exported *) module type IntervalSig = sig type t val create : int -> int -> t end module Interval : IntervalSig = struct type t = Empty | Range of int * int let create lo hi = if (lo <= hi) then Range(lo, hi) else Empty end module type ExtendedIntervalSig = sig include IntervalSig val contains : t - > int -> bool end module ExtendedInterval : ExtendedIntervalSig = struct include Interval let contains intvl x = match intvl with | Empty -> false | Range(lo, hi) -> lo <= x && x <= hi end (* Attempt 2: Works, becuase implementation exported as part of signature *) module type IntervalSig = sig type t = Empty | Range of int * int val create : int -> int -> t end module Interval : IntervalSig = struct type t = Empty | Range of int * int let create lo hi = if (lo <= hi) then Range(lo, hi) else Empty end module type ExtendedIntervalSig = sig include IntervalSig val contains : t -> int -> bool end module ExtendedInterval : ExtendedIntervalSig = struct include Interval let contains intvl x = match intvl with | Empty -> false | Range(lo, hi) -> lo <= x && x <= hi end (* Attempt 3: Does not work, because open only imports the names, but does not extend the structure *) module type IntervalSig = sig type t = Empty | Range of int * int val create : int -> int -> t end module Interval : IntervalSig = struct type t = Empty | Range of int * int let create lo hi = if (lo <= hi) then Range(lo, hi) else Empty end module type ExtendedIntervalSig = sig include IntervalSig val contains : t -> int -> bool end module ExtendedInterval : ExtendedIntervalSig = struct open Interval let contains intvl x = match intvl with | Empty -> false | Range(lo, hi) -> lo <= x && x <= hi end (** - open, include - open is a mechanism to extend the scope. Makes names available, but does not re-export them. - include is a mechanism to extend the structure / signature. Re-exports all names. - #use, #load - #use refers to syntactic copy-paste. *) (** Classes vs modules class Rectangle { int x, y, len, height; int area() { } } Rectangle r = new Rectangle(x=3, y=2, len=5, height=6) *)