Signature file using ppx and functors


#1

Hi,

I am new to OCaml and am writing the following implementation in a .ml file, using Core and ppx_jane:

open Core

module T = struct
  type 'a t =
    | Case1
    | Case2 of 'a
  [@@deriving compare, sexp]
end

include T

include Comparable.Make(T)

My question is what the .mli signature file would look like.

Thanks!


#2

You can use the @@deriving features from ppx_jane in the signature too:

module T : sig
  type 'a t =
  | Case1
  | Case2 of 'a
  [@@deriving compare, sexp]
end

The above gets rewritten to something like:

module T : sig
  type 'a t =
  | Case1
  | Case2 of 'a

  val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int

  val sexp_of_t : ('a -> Sexp.t) -> 'a t -> Sexp.t
  val t_of_sexp : (Sexp.t -> 'a) -> Sexp.t -> 'a t
end

I don’t think Comparable can be used with polymorphic types, however. If it could, the rest of the signature might look like:

include T
include Comparable.S1

#3

Almost. I think that last declaration should look like:

type 'a t
include Comparable.S1 with type 'a t := 'a t