diff options
| author | ppedrot | 2013-11-13 15:37:23 +0000 |
|---|---|---|
| committer | ppedrot | 2013-11-13 15:37:23 +0000 |
| commit | 2fff9290c2da7e815606673bd532a8755fe66dee (patch) | |
| tree | 950420222cde691276cf466999cf1a7e4ee8a595 /lib | |
| parent | 5cea75bd0f028fcea20b7cb4a058202187f5ddcd (diff) | |
Adding an unsafe mapping function to maps.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@17085 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/cMap.ml | 19 | ||||
| -rw-r--r-- | lib/cMap.mli | 8 |
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/cMap.ml b/lib/cMap.ml index 952ec21c69..d8cd2d779a 100644 --- a/lib/cMap.ml +++ b/lib/cMap.ml @@ -22,6 +22,10 @@ sig val modify : key -> (key -> 'a -> 'a) -> 'a t -> 'a t val domain : 'a t -> Set.t val bind : (key -> 'a) -> Set.t -> 'a t + module Unsafe : + sig + val map : (key -> 'a -> key * 'b) -> 'a t -> 'b t + end end module MapExt (M : Map.OrderedType) : @@ -31,6 +35,10 @@ sig val modify : M.t -> (M.t -> 'a -> 'a) -> 'a map -> 'a map val domain : 'a map -> Set.Make(M).t val bind : (M.t -> 'a) -> Set.Make(M).t -> 'a map + module Unsafe : + sig + val map : (M.t -> 'a -> M.t * 'b) -> 'a map -> 'b map + end end = struct (** This unsafe module is a way to access to the actual implementations of @@ -91,6 +99,17 @@ struct map_inj (MNode (bind f l, k, f k, bind f r, h)) (** Dual operation of [domain]. *) + module Unsafe = + struct + + let rec map f (s : 'a map) : 'b map = match map_prj s with + | MEmpty -> map_inj MEmpty + | MNode (l, k, v, r, h) -> + let (k, v) = f k v in + map_inj (MNode (map f l, k, v, map f r, h)) + + end + end module Make(M : Map.OrderedType) = diff --git a/lib/cMap.mli b/lib/cMap.mli index 6e5f3bcfdd..6b61782b05 100644 --- a/lib/cMap.mli +++ b/lib/cMap.mli @@ -39,6 +39,14 @@ sig (** [bind f s] transform the set [x1; ...; xn] into [x1 := f x1; ...; xn := f xn]. *) + module Unsafe : + sig + val map : (key -> 'a -> key * 'b) -> 'a t -> 'b t + (** As the usual [map], but also allows to modify the key of a binding. + It is required that the mapping function [f] preserves key equality, + i.e.: for all (k : key) (x : 'a), compare (fst (f k x)) k = 0. *) + end + end module Make(M : Map.OrderedType) : ExtS with |
