package dmap

  1. Overview
  2. Docs
A library that implements dependent (heterogeneous) maps

Install

Dune Dependency

Authors

Maintainers

Sources

dmap-0.5.tar.gz
md5=fe62cbaa5916073a175b6f3b32dc8b68
sha512=9bbb186dc6d94e3f7ba5f64e74cb66cd13d5a5ff10b1924367a6629b49c9943a1f65ff65d5fe49a8fcfd69f15ddf4a4c93e0bf654cef781296576deace554d9b

doc/dmap/Dmap/index.html

Module DmapSource

Dependent (or heterogeneous) association tables over ordered types.

This module implements applicative association tables, also known as finite maps or dictionaries, given a total ordering function over the keys. The particularity is that the types of the values recorded in the tables may vary, depending on the keys, hence the name heterogeneous (or dependent) maps.

All operations over maps are purely applicative (no side-effects). The implementation uses balanced binary trees, and therefore searching and insertion take time logarithmic in the size of the map.

For instance:

  module IntBool = struct
    (* The type for the keys of our maps. The index ['a] denotes the type
       of the values that will be associated to the keys. In the case of
       the [Int] constructor, the map will expect data of type [string].
       In the case of the [Bool] constructor, the map will expect values
       of type [char].
    *)
    type 'a t = Int : int -> string t | Bool : bool -> char t

    (* Total order on values of type [_ t]. *)
    let compare (type a1 a2) (v1 : a1 t) (v2 : a2 t) : (a1, a2) cmp =
      match (v1, v2) with
      | Int n1, Int n2 -> if n1 = n2 then Eq else if n1 < n2 then Lt else Gt
      | Bool b1, Bool b2 ->
          if b1 = b2 then Eq else if (not b1) || b2 then Lt else Gt
      | Bool _, Int _ -> Lt
      | Int _, Bool _ -> Gt
  end

  (* We create a module of maps whose keys have type [IntBool.t] *)
  module IntBoolMap = Dmap.Make(IntBool)

  (* Definition of a map of type [IntBoolMap.t]. *)
  let m = IntBoolMap.(empty |> add (Int 42) "hello" |> add (Bool true) 'A')

  (* Some queries on the map [m] *)
  let () =
    assert (IntBoolMap.find_opt (Int 42) m = Some "hello");
    assert (IntBoolMap.find_opt (Bool true) m = Some 'A');
    assert (IntBoolMap.find_opt (Bool false) m = None)

This creates a new module IntBoolMap, with a new type IntBoolMap.t of maps from IntBool.t to string or char. As specified by the GADT definition of IntBool.t, the values associated to the keys of the form Int n have type string, and the values associated to the keys of the form Bool b have type char.

Sourcetype (_, _) cmp =
  1. | Lt : ('a, 'b) cmp
  2. | Eq : ('a, 'a) cmp
  3. | Gt : ('a, 'b) cmp

The type of comparisons: ('a, 'b) cmp denotes comparisons between values of types 'a and 'b. The types 'a and 'b might be different. Lt denotes "lesser than", Eq denotes "equal", and Gt denotes "greater than". When the Eq constructor is used, we learn that 'a and 'b are the same.

Sourcemodule type DORDERED = sig ... end

The signature of dependently-ordered types. This is the input signature of the functor Make.

Sourcemodule type S_WITH_VALUE = sig ... end

Output signature of the functor MakeWithValue.

Sourcemodule type S = S_WITH_VALUE with type 'a value := 'a

Output signature of the functor Make.

Sourcemodule type TYPE1 = sig ... end

Signature for types with 1 parameter.

Sourcemodule MakeWithValue (Ord : DORDERED) (Val : TYPE1) : S_WITH_VALUE with type 'a key = 'a Ord.t and type 'a value = 'a Val.t

Functor building an implementation of the dependent map structure given a totally ordered type of indexed keys and a type of values.

Sourcemodule Make (Ord : DORDERED) : S with type 'a key = 'a Ord.t

Functor building an implementation of the dependent map structure given a totally ordered type of indexed keys.

Sourcemodule ToOrdered (X : DORDERED) : sig ... end

Functor that converts a DORDERED into an ordered type

Sourcemodule MakeMap (X : DORDERED) : Map.S with type key = ToOrdered(X).t and type 'a t = 'a Map.Make(ToOrdered(X)).t

Functor that creates a non-dependendent map for keys of a DORDERED type

Functor that creates a set of values of a DORDERED type

Sourcemodule Extend (X : DORDERED) (F : sig ... end) : sig ... end

Functor that extends the indices of a DORDERED type, given some type-level function

Sourcemodule ExtendL (X : DORDERED) (Y : sig ... end) : sig ... end

Functor that extends the indices of a DORDERED type by adding some data to its left-hand side

Sourcemodule ExtendR (X : DORDERED) (Y : sig ... end) : sig ... end

Functor that extends the indices of a DORDERED type by adding some data to its right-hand side

OCaml

Innovation. Community. Security.