How can I use the output signature of a functor in an interface file?

176 views Asked by At

If I have an implementation (.re) file containing

module IntMap =
  Map.Make {
    type t = int;
    let compare = compare;
  };

type foo = IntMap.t string;

how can I add the signature of foo to the interface (.rei) file? In analogy with OCaml's

module IntMap = Map.S with type key = int
type foo = string IntMap.t

I expected it to be

module IntMap =
  Map.S {
    type t = int;
  };

type foo = IntMap.t string;

but that results in a syntax error at {.

1

There are 1 answers

1
glennsl On BEST ANSWER

I suspect the root cause of your problem is that the OCaml code you posted is not valid. It should be

module IntMap: Map.S with type key = int

The Reason equivalent then is

module IntMap: Map.S with type key = int;
type foo = IntMap.t string;

Not very different :)

Also, in case you're not aware of it, reason-tools is a great tool that will convert between Reason and OCaml for you. It does require valid input though ;)