Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Why3
why3
Commits
c67eb1af
Commit
c67eb1af
authored
Nov 09, 2010
by
François Bobot
Browse files
stdlib : add Map.mapi_fold
parent
de5783d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/util/stdlib.ml
View file @
c67eb1af
...
...
@@ -56,6 +56,8 @@ module type S =
val
union
:
(
key
->
'
a
->
'
a
->
'
a
option
)
->
'
a
t
->
'
a
t
->
'
a
t
val
inter
:
(
key
->
'
a
->
'
a
->
'
a
option
)
->
'
a
t
->
'
a
t
->
'
a
t
val
find_default
:
key
->
'
a
->
'
a
t
->
'
a
val
mapi_fold
:
(
key
->
'
a
->
'
acc
->
'
acc
*
'
b
)
->
'
a
t
->
'
acc
->
'
acc
*
'
b
t
end
module
Make
(
Ord
:
OrderedType
)
=
struct
...
...
@@ -388,6 +390,17 @@ module Make(Ord: OrderedType) = struct
else
find_default
x
def
(
if
c
<
0
then
l
else
r
)
let
rec
mapi_fold
f
m
acc
=
match
m
with
Empty
->
acc
,
Empty
|
Node
(
l
,
v
,
d
,
r
,
h
)
->
let
acc
,
l'
=
mapi_fold
f
l
acc
in
let
acc
,
d'
=
f
v
d
acc
in
let
acc
,
r'
=
mapi_fold
f
r
acc
in
acc
,
Node
(
l'
,
v
,
d'
,
r'
,
h
)
end
end
src/util/stdlib.mli
View file @
c67eb1af
...
...
@@ -217,6 +217,10 @@ module type S =
(** [find_default x d m] returns the current binding of [x] in [m],
or return [d] if no such binding exists. *)
val
mapi_fold
:
(
key
->
'
a
->
'
acc
->
'
acc
*
'
b
)
->
'
a
t
->
'
acc
->
'
acc
*
'
b
t
(** fold and map at the same time *)
end
(** Output signature of the functor {!Map.Make}. *)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment