]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/ocaml/contrib/ocamlbuild/bool.ml
Update
[l4.git] / l4 / pkg / ocaml / ocaml / contrib / ocamlbuild / bool.ml
1 (***********************************************************************)
2 (*                             ocamlbuild                              *)
3 (*                                                                     *)
4 (*  Nicolas Pouillard, Berke Durak, projet Gallium, INRIA Rocquencourt *)
5 (*                                                                     *)
6 (*  Copyright 2007 Institut National de Recherche en Informatique et   *)
7 (*  en Automatique.  All rights reserved.  This file is distributed    *)
8 (*  under the terms of the Q Public License version 1.0.               *)
9 (*                                                                     *)
10 (***********************************************************************)
11
12
13 (* Original author: Berke Durak *)
14 (* Bool *)
15
16 type 'a boolean = And of 'a boolean list | Or of 'a boolean list | Not of 'a boolean | Atom of 'a | True | False;;
17
18 let rec eval f = function
19   | And l -> List.for_all (eval f) l
20   | Or l -> List.exists (eval f) l
21   | Not x -> not (eval f x)
22   | Atom a -> f a
23   | True -> true
24   | False -> false
25 ;;
26 let rec iter f = function
27   | (And l|Or l) -> List.iter (iter f) l
28   | Not x -> iter f x
29   | Atom a -> f a
30   | True|False -> ()
31 ;;
32 let rec map f = function
33   | And l -> And(List.map (map f) l)
34   | Or l -> Or(List.map (map f) l)
35   | Not x -> Not(map f x)
36   | Atom a -> Atom(f a)
37   | (True|False) as b -> b
38 ;;