summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Scherer <gabriel.scherer@gmail.com>2014-05-03 13:24:29 +0000
committerGabriel Scherer <gabriel.scherer@gmail.com>2014-05-03 13:24:29 +0000
commitc03e1558853690150a203e16f2017ca924642f95 (patch)
tree182530c51d0ae892fc44c19a22864cedf98dda8f
parentc31d2ab685c0d2dcea1d3e779cc756b3c006f4ed (diff)
stdlib/map: Add some usage exemple in the documentation.
(Patch by Nicolas Braud-Santoni) git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14730 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--stdlib/map.mli20
-rw-r--r--stdlib/set.mli21
2 files changed, 41 insertions, 0 deletions
diff --git a/stdlib/map.mli b/stdlib/map.mli
index 6dd371b52..abf453161 100644
--- a/stdlib/map.mli
+++ b/stdlib/map.mli
@@ -19,6 +19,26 @@
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 IntPairs =
+ struct
+ type t = int * int
+ let compare (x0,y0) (x1,y1) =
+ match Pervasives.compare x0 x1 with
+ 0 -> Pervasives.compare y0 y1
+ | c -> c
+ end
+
+ module PairsMap = Map.Make(IntPairs)
+
+ let m = PairsMap.(empty |> add (0,1) "hello" |> add (1,0) "world")
+ ]}
+
+ This creates a new module [PairsMap], with a new type ['a PairsMap.t]
+ of maps from [int * int] to ['a]. In this example, [m] contains [string]
+ values so its type is [string PairsMap.t].
*)
module type OrderedType =
diff --git a/stdlib/set.mli b/stdlib/set.mli
index 556ee9388..1b67398ee 100644
--- a/stdlib/set.mli
+++ b/stdlib/set.mli
@@ -19,6 +19,27 @@
The implementation uses balanced binary trees, and is therefore
reasonably efficient: insertion and membership take time
logarithmic in the size of the set, for instance.
+
+ The [Make] functor constructs implementations for any type, given a
+ [compare] function.
+ For instance:
+ {[
+ module IntPairs =
+ struct
+ type t = int * int
+ let compare (x0,y0) (x1,y1) =
+ match Pervasives.compare x0 x1 with
+ 0 -> Pervasives.compare y0 y1
+ | c -> c
+ end
+
+ module PairsSet = Set.Make(IntPairs)
+
+ let m = PairsSet.(empty |> add (2,3) |> add (5,7) |> add (11,13))
+ ]}
+
+ This creates a new module [PairsSet], with a new type [PairsSet.t]
+ of sets of [int * int].
*)
module type OrderedType =