Module Generalised_signatures.Indexable

A type of indexable containers with parametric element type, such as array.

module type Indexable1 = sig ... end
module Array : Indexable1 with type 'a t = 'a array

A type of indexable containers with fixed element type, such as string.

module type Indexable0 = sig ... end
module String : Indexable0 with type t = string and type elt = char

A signature that generalises both Indexable1 and Indexable0.

module type IndexableN = sig ... end

We can use functors to demonstrate that IndexableN is indeed a generalisation of the other two:

module Indexable0_to_N (X : Indexable0) : IndexableN with type 'a t = X.t and type 'a elt = X.elt

Indexable0 is a special-case of IndexableN.

module Indexable1_to_N (X : Indexable1) : IndexableN with type 'a t = 'a X.t and type 'a elt = 'a

Indexable1 is a special-case of IndexableN.

We can now define some behaviours on top of IndexableN:

module Foldable_of_indexable (I : IndexableN) : sig ... end

... and then apply this functor to both of our Indexable containers:

module Array_foldable : sig ... end
module String_foldable : sig ... end