package gmap
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=04dd9e6226ac8f8fb4ccb6021048702e34a482fb9c1d240d3852829529507c1c
sha512=71616981f5a15d6b2a47e18702083e52e81f6547076085b1489f676f50b0cc47c7c2c4fa19cb581e2878dc3d4f7133d0c50d8b51a8390be0e6e30318907d81d3
Description
Added to opam-repository:
README
Gmap - heterogenous maps over a GADT
0.3.0
Gmap exposes the functor Make which takes a key type (a GADT 'a key) and outputs a type-safe Map where each 'a key is associated with a 'a value. This removes the need for additional packing. It uses OCaml's stdlib Map data structure.
type _ key =
| I : int key
| S : string key
module K = struct
type 'a t = 'a key
let compare : type a b. a t -> b t -> (a, b) Gmap.Order.t = fun t t' ->
let open Gmap.Order in
match t, t' with
| I, I -> Eq | I, _ -> Lt | _, I -> Gt
| S, S -> Eq
end
module M = Gmap.Make(K)
let () =
let m = M.empty in
...
match M.find I m with
| Some x -> Printf.printf "got %d\n" x
| None -> Printf.printf "found nothing\n"This is already an exhaustive pattern match: there is no need for another case (for the constructor B) since the type system knows that looking for A will result in an int.
Motivation came from parsing of protocols which usually specify optional values and extensions via a tag-length-value (TLV) mechanism: for a given tag the structure of value is different - see for example IP options, TCP options, DNS resource records, TLS hello extensions, etc.
Discussing this problem with Justus Matthiesen during summer 2017, we came up with this design. Its main difference to Daniel C. Bünzli's hmap is that in gmap the key-value GADT type must be provided when instantiating the functor. In hmap, keys are created dynamically.
Documentation
API documentation is available online.
Installation
You need opam installed on your system. The command
opam install gmap
will install this library.
Optional Dependencies
None
Conflicts
None
Build status
Results of building gmap with each compiler on check.ci.ocaml.org, run of against opam-repository 7cdc698. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.3.0 (this version) | good | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure