module type Store = sig
type data
val save :
key:string -> data -> (unit, error) Lwt_result.t
val read :
key:string-> (data, error) Lwt_result.t
end
and I have both a db and in memory implementation:
module Make (D : SerializableData) : Store with type data := D.t = struct
let my_data = ref (...)
let save ~key ~data = ...
let read ~key = ...
end
Now, for the tests, in db it’s easy to clear the data (just clean up the db), but for the in memory, I would like to add a clear method that clear my_data on the in memory implementation, but I have no idea how.
I tried moving let my_data = ref... outside of the functor but then the types don’t match anymore.
I meant shrinking the module-type. as in having a module with e.g. 20 val/type definitions and wanting to have another module with 19, excluding one by name, without having to spell out the other 19’s types in a new signature in order to ascribe the 20-vals module to it.
sorry for not being quite clear in my wording haha
Yeah but this is quite restrictive (you need to specify the resulting module type rather than generating it via a hiding operation)
I realize this might not be that practically useful in real world code – evident by how well big codebases gone by with good expressiveness and without needing it. I’m just curious about whether it was ever considered and subsequently rejected (from a design standpoint), or if it’s just not a thing.
module type Store = sig
type data
val save :
key:string -> data -> (unit, error) Lwt_result.t
val read :
key:string-> (data, error) Lwt_result.t
end
module type TestStore = sig
include Store
val clear -> unit -> unit
end
module MakeTest (D: SerializableData) : TestStore with type data := D.t = struct
...
end
module Make (D: SerializableData) : Store with type data := D.t = MakeTest (D: SerializableData)