I need to do the following:
open Core
module Foo : sig
type t = string [@@deriving compare, sexp, jsonaf]
include Comparable.S with type t := t
end = struct
module T = struct
type t = string [@@deriving compare, sexp, jsonaf]
end
include T
include Comparable.Make (T)
end
module Bar = struct
type t = { foo : int Foo.Map.t } [@@deriving compare, sexp, jsonaf]
end
but this fails with:
File "test.ml", line 15, characters 23-32:
15 | type t = { foo : int Foo.Map.t } [@@deriving compare, sexp, jsonaf]
^^^^^^^^^
Error: Unbound value Foo.Map.t_of_jsonaf
I can provide the serializers easily enough with this module:
module Map_with_jsonaf : sig
include Map.S with type Key.t = Foo.t
val t_of_jsonaf : (Jsonaf.t -> 'a) -> Jsonaf.t -> 'a t
val jsonaf_of_t : ('a -> Jsonaf.t) -> 'a t -> Jsonaf.t
end = struct
include Map.Make (Foo)
module Assoc_list = struct
type 'a t = (string * 'a) list [@@deriving jsonaf]
end
let t_of_jsonaf (a_of_json : Jsonaf.t -> 'a) (json : Jsonaf.t) : 'a t =
Assoc_list.t_of_jsonaf a_of_json json |> of_alist_exn
;;
let jsonaf_of_t (a_to_json : 'a -> Jsonaf.t) (t : 'a t) : Jsonaf.t =
t |> Map.to_alist |> Assoc_list.jsonaf_of_t a_to_json
;;
end
but I need this Map module to extend the Comparable.S
signature. In the signature of Foo
I want to do something like include Comparable.S with Map := Map_with_jsonaf
. I’ve tried various permutations but can’t get this to work. Is it possible?