Type + 'at in the Ocaml Map Library?

I work with the built-in Map Ocaml library for a set of problems, and I am having problems accessing the data type of the map itself. This is supposed to be the third implementation of the dictionary (the first two are a list and an asymmetric binary search tree), and part of the functor I have to implement is the “dict type”, which is the type of the actual dictionary. For the list, enter dict (List D.key * D.value); for wood, type dict was empty | Branch ((D.key * D.value), dict, dict). The Ocaml documentation says:

type +'a t 
The type of maps from type key to type 'a.

This is similar to what I need, but I cannot use it correctly. M is my Map.Make module, by the way. I tried

type dict = M.t
type dict = M.+D.value t
type dict = M.+

But I keep getting error messages. Can anyone help? Many thanks!

+5
source share
2 answers

+is an annotation of variance; it is not part of the name. The syntax for a parameterized type is: param typeor (param, param, ...) typein OCaml: int list, (int, string) Hashbl.t. Here you want D.value M.t.

+7
source

You can recognize yourself by requesting the ocaml compiler: ocamlc -i file.ml

To create a map using Map.Make from the ocaml standard library, this file will look like this (for a map from int to 'a):

module Intmap = Map.Make (struct
   type t = int
   let compare = Pervasives.compare
end)

The ocaml compiler will give you something like this (when called ocamlc -i mymap.ml):

module Intmap :
   sig
      type key = int
      type +'a t
      val empty : 'a t
      ...
end
+4
source

All Articles