Skip to content
Snippets Groups Projects
Commit bc9e7b45 authored by Valentin Perrelle's avatar Valentin Perrelle Committed by David Bühler
Browse files

[Kernel] Add iterators uniformly to all Lattice_bounds submodules

parent 02aa10e3
No related branches found
No related tags found
No related merge requests found
...@@ -126,6 +126,10 @@ module Bottom = struct ...@@ -126,6 +126,10 @@ module Bottom = struct
(* Iterators *) (* Iterators *)
let bind f = function
| `Bottom -> `Bottom
| `Value v -> f v
let fold ~bottom f = function let fold ~bottom f = function
| `Bottom -> bottom | `Bottom -> bottom
| `Value v -> f v | `Value v -> f v
...@@ -170,17 +174,11 @@ module Bottom = struct ...@@ -170,17 +174,11 @@ module Bottom = struct
module Operators = module Operators =
struct struct
let (>>-) t f = match t with let (>>-) x f = bind f x
| `Bottom -> `Bottom let (>>-:) x f = map f x
| `Value t -> f t let (let+) x f = map f x
let (>>-:) t f = match t with
| `Bottom -> `Bottom
| `Value t -> `Value (f t)
let (let+) = (>>-:)
let (and+) = zip let (and+) = zip
let (let*) = (>>-) let (let*) x f = bind f x
let (and*) = zip let (and*) = zip
end end
...@@ -249,6 +247,20 @@ struct ...@@ -249,6 +247,20 @@ struct
| `Top, v | v, `Top -> v | `Top, v | v, `Top -> v
| `Value vx, `Value vy -> `Value (narrow_value vx vy) | `Value vx, `Value vy -> `Value (narrow_value vx vy)
(* Iterators *)
let bind f = function
| `Top -> `Top
| `Value v -> f v
let fold ~top f = function
| `Top -> top
| `Value v -> f v
let map f = function
| `Top -> `Top
| `Value v -> `Value (f v)
(** Combination *) (** Combination *)
let zip x y = let zip x y =
...@@ -264,18 +276,13 @@ struct ...@@ -264,18 +276,13 @@ struct
(** Operators *) (** Operators *)
module Operators = struct module Operators =
let (>>-) t f = match t with struct
| `Top -> `Top let (>>-) x f = bind f x
| `Value t -> f t let (>>-:) x f = map f x
let (let+) x f = map f x
let (>>-:) t f = match t with
| `Top -> `Top
| `Value t -> `Value (f t)
let (let+) = (>>-:)
let (and+) = zip let (and+) = zip
let (let*) = (>>-) let (let*) x f = bind f x
let (and*) = zip let (and*) = zip
end end
end end
...@@ -299,6 +306,23 @@ struct ...@@ -299,6 +306,23 @@ struct
| `Bottom, _ | _, `Bottom -> `Bottom | `Bottom, _ | _, `Bottom -> `Bottom
| `Value vx, `Value vy -> (narrow_value vx vy :> 'a t) | `Value vx, `Value vy -> (narrow_value vx vy :> 'a t)
(* Iterators *)
let bind f = function
| `Top -> `Top
| `Bottom -> `Bottom
| `Value v -> f v
let fold ~top ~bottom f = function
| `Top -> top
| `Bottom -> bottom
| `Value v -> f v
let map f = function
| `Top -> `Top
| `Bottom -> `Bottom
| `Value v -> `Value (f v)
(** Combination *) (** Combination *)
let zip x y = let zip x y =
...@@ -309,20 +333,13 @@ struct ...@@ -309,20 +333,13 @@ struct
(** Operators *) (** Operators *)
module Operators = struct module Operators =
let (>>-) t f = match t with struct
| `Top -> `Top let (>>-) x f = bind f x
| `Bottom -> `Bottom let (>>-:) x f = map f x
| `Value t -> f t let (let+) x f = map f x
let (>>-:) t f = match t with
| `Top -> `Top
| `Bottom -> `Bottom
| `Value t -> `Value (f t)
let (let+) = (>>-:)
let (and+) = zip let (and+) = zip
let (let*) = (>>-) let (let*) x f = bind f x
let (and*) = zip let (and*) = zip
end end
end end
...@@ -82,7 +82,8 @@ module Bottom : sig ...@@ -82,7 +82,8 @@ module Bottom : sig
(* Iterators *) (* Iterators *)
val iter: ('a -> unit) -> 'a t -> unit val iter: ('a -> unit) -> 'a t -> unit
val fold: bottom: 'b -> ('a -> 'b) -> 'a t -> 'b val bind: ('a -> 'b t) -> 'a t -> 'b t
val fold: bottom:'b -> ('a -> 'b) -> 'a t -> 'b
val map: ('a -> 'b) -> 'a t -> 'b t val map: ('a -> 'b) -> 'a t -> 'b t
(* Combination *) (* Combination *)
...@@ -144,6 +145,12 @@ module Top : sig ...@@ -144,6 +145,12 @@ module Top : sig
val join: ('a -> 'a -> 'a t) -> 'a t -> 'a t -> 'a t val join: ('a -> 'a -> 'a t) -> 'a t -> 'a t -> 'a t
val narrow: ('a -> 'a -> 'a) -> 'a t -> 'a t -> 'a t val narrow: ('a -> 'a -> 'a) -> 'a t -> 'a t -> 'a t
(* Iterators *)
val iter: ('a -> unit) -> 'a t -> unit
val bind: ('a -> 'b t) -> 'a t -> 'b t
val fold: top:'b -> ('a -> 'b) -> 'a t -> 'b
val map: ('a -> 'b) -> 'a t -> 'b t
(** Combination *) (** Combination *)
val zip: 'a t -> 'b t -> ('a * 'b) t (* `Top if any is `Top *) val zip: 'a t -> 'b t -> ('a * 'b) t (* `Top if any is `Top *)
...@@ -188,4 +195,10 @@ module TopBottom: sig ...@@ -188,4 +195,10 @@ module TopBottom: sig
(* Lattice operators *) (* Lattice operators *)
val join: ('a -> 'a -> [< 'a t]) -> 'a t -> 'a t -> 'a t val join: ('a -> 'a -> [< 'a t]) -> 'a t -> 'a t -> 'a t
val narrow: ('a -> 'a -> [< 'a t]) -> 'a t -> 'a t -> 'a t val narrow: ('a -> 'a -> [< 'a t]) -> 'a t -> 'a t -> 'a t
(* Iterators *)
val iter: ('a -> unit) -> 'a t -> unit
val bind: ('a -> 'b t) -> 'a t -> 'b t
val fold: top:'b -> bottom:'b -> ('a -> 'b) -> 'a t -> 'b
val map: ('a -> 'b) -> 'a t -> 'b t
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment