Hi everyone,
I am new to Ocaml and functional programming. I have been working on a toy project where I am trying to get comfortable with the Ocaml module system. Btw, I am using the jane street base library.
Basically, I have a module of type:
module type CONFIG = sig
type 'a t
val tCol : 'a t -> 'a
val fCol : 'a t -> 'a list
val makeCol : 'a -> 'a list -> 'a t
end
And a Functor that maps over the Comparator.S
module.
module MakeConfig (C : Comparator.S) = struct
type 'a t =
{
tcol : 'a;
fcol : ('a, C.comparator_witness) Set.t
}
let tCol { tcol = tocolumn; fcol = _ } = tocolumn
let fCol { tcol = _; fcol = fromcolumn } = Set.to_list fromcolumn
let makeCol t_col f_col =
{
tcol = t_col;
fcol = Set.of_list (module C) f_col
}
end
This allows me to make modules with multiple implementations of the Comparator
e.g.
module StringConfig = MakeConfig (String)
How do I go about about adding the module type signature? I am trying to do something like this,
module StringConfig : CONFIG with type 'a t = string t = MakeConfig (String)
Is this possible in Ocaml with the record type? Or if there is a better way to design the type.
Thanks,