Map
Maps from keys to values, where the bindings key/value are ordered by increasing keys.
type t<key, value> = map<key, value>
The type t<key, value>
is an alias for map<key,value>
.
let empty: <key, value>t<key, value>
The value empty
is the empty map. In some contexts, it is
useful to annotate it with its type, for example:
(empty as map<int, string>)
.
let get_and_update: <key, value>(_: key) => (_: option<value>) => (_: t<key, value>) => [option<value>, t<key, value>]
The call get_and_update(key, None(), map)
returns a copy of the
map map
without the entry for the key key
in map
(no change
if the key is absent). The call get_and_update(key, Some(value),
map)
returns a copy of the map map
where there is an entry for
the key key
associated with the value value
. In both cases, if
there was already a value v
bound to key
, it is returned as
Some(v)
, otherwise None()
.
let update: <key, value>(_: key) => (_: option<value>) => (_: t<key, value>) => t<key, value>
The call update(key, None(), map)
returns a copy of the map map
without the entry for the key key
in map
(no change if the key
is absent). The call update(key, Some(value), map)
returns the map
map
where there is an entry for the key key
associated with
the value value
. In both cases, the value originally bound to
key
is lost. See get_and_update
.
let add: <key, value>(_: key) => (_: value) => (_: t<key, value>) => t<key, value>
The call add(key, value, map)
returns a copy of the map
where
there is a binding of key key
to value value
. If there is a
binding for key
in map
, then it is lost.
let remove: <key, value>(_: key) => (_: t<key, value>) => t<key, value>
The call remove(key, map)
returns a copy of the map map
where
the binding for key key
is absent.
let literal: <key, value>(_: list<[key, value]>) => t<key, value>
The call literal(list[[k1,v1], ..., [kn,vn]])
returns a map from
the pairs of key/value in the list. Note: The list must be a
literal, not an expression (compile-time list of values).
let of_list: <key, value>(_: list<[key, value]>) => t<key, value>
The call of_list(bindings)
returns a map from the pairs of
key/value in the list bindings
. Note: Use literal
instead if
using a literal list.
let size: <key, value>(_: t<key, value>) => nat
The call size(map)
evaluates in the number of entries in the
map map
.
let mem: <key, value>(_: key) => (_: t<key, value>) => bool
The call mem(key, map)
is true
if, and only if, the key key
is in the map map
.
let find_opt: <key, value>(_: key) => (_: t<key, value>) => option<value>
The call find_opt(key, map)
returns None()
if the key key
is
present in the map map
; otherwise, it is Some(v)
, where v
is
the value associated to key
in map
.
let find: <key, value>(_: key) => (_: t<key, value>) => value
The call find(key, map)
returns the value associated to key
in
map
. If the key is absent, the execution fails with the string
"MAP FIND"
.
let fold: <key, value, acc>(_: (_: [acc, [key, value]]) => acc) => (_: t<key, value>) => (_: acc) => acc
The call fold(f, map, init)
is
f (... f (f (init, [k1,v1]), [k2,v2]), ..., [kn,vn])
where [k1,v1]
, [k2,v2]
, ..., [kn,vn]
are the bindings in the
map map
, in increasing order of the keys k1
, k2
, ..., and kn
.
let iter: <key, value>(_: (_: [key, value]) => unit) => (_: t<key, value>) => unit
The call iter(f, map)
is {f (k1,v1); (k2,v2); ...; f (kn,vn);}
.
let map: <key, value, new_value>(_: (_: [key, value]) => new_value) => (_: t<key, value>) => t<key, new_value>
The call map(f, m)
, where the map m
contains the bindings
[k1,v1]
, [k2,v2]
, ..., and [kn,vn]
in increasing order of
the keys, is the map containing the bindings [k1, f (k1,v1)]
,
[k2, f (k2,v2)]
, ..., [kn, f (kn,vn)]
.