I had thought to write a post about how there are no examples I could find about what goes into a module to accept a functor. Anyway, I thought I’d give chatgpt a go and much to my surprise it got it right.
so now could someone explain what comes after the : … I’m guessing it’s some sort of type, but I’ve never seen any description of types that include “with” clauses … (?).
module Make (Ord : OrderedType) : S with type key = Ord.key and type value = Ord.value =
struct
type key = Ord.key
type value = Ord.value
type t = (key * value) list
I note I can completely remove the : S … up to the = struct and it still compiles.
S with type t1 = t2 replaces type t1 (abstract type) in S by type t1 = t2. S with type t1 := t2 removes type t1 (abstract type) from S and replaces t1 by t2 everywhere in S. In your example, you are restricting the result of Make to only expose what’s in S, if you remove the : S ... part the result exposes everything. Where the with type specifications are indispensable, is for building signatures (i.e. module type) using include clauses.