I am trying to implement a Trie that is generic over the types of its keys and values using Map.Make. This functor takes a Map.OrderedType and produces a module with a bunch of Map utilities defined inside it. However, the return module type of Map.Make is anonymous. I want to expose the particular Map implementation that my Trie is using under the hood in my TrieType module type.
Is there a way to refer to the return module type of Map.Make? Alternatively, is it possible to use something similar to transparent ascription in SML to expose the module M without insisting on a particular module type for it or hiding any of its members?
module OrderedStringType : Map.OrderedType = struct
type t = string
let compare = String.compare
end
module type TrieType = sig
(* I want to expose the M submodule in the interface, but its
* module type is anonymous *)
(* here is some strawman syntax *)
(* module M : Map.Make(Set.OrderedType) *)
type 'a t
end
module Trie(X : Map.OrderedType) : TrieType = struct
module M = Map.Make(X)
type 'a t = EmptyTrie | Trie of 'a tChild
and 'a tChild = {value : 'a option ; children : 'a t M.t}
end
module TruncatedTrie(X : TrieType) = struct
(* Implementation to follow *)
end
String.compare. The<and>operators are no less polymorphic than the polymorphiccomparefunction.) OCaml has a constructmodule type of ...that might do what you want, but I can't tell. - Jeffrey ScofieldMap.Makeis applied to a module satisfyingMap.OrderedType. It sounds like usingmodule type ofI could recover it using a particular instance ofMap.OrderedType... - Gregory Nisbet