]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/lib/cps.ml
we removed some old code and fixed a reduction bug: two instances fo the
[helm.git] / helm / software / lambda-delta / lib / cps.ml
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department, University of Bologna, Italy.                     
5     ||I||                                                                
6     ||T||  HELM is free software; you can redistribute it and/or         
7     ||A||  modify it under the terms of the GNU General Public License   
8     \   /  version 2 or (at your option) any later version.              
9      \ /   This software is distributed as is, NO WARRANTY.              
10       V_______________________________________________________________ *)
11
12 let start x = x
13
14 let id f x = f x
15
16 let rec list_sub_strict f l1 l2 = match l1, l2 with
17    | _, []              -> f l1
18    | _ :: tl1, _ :: tl2 -> list_sub_strict f tl1 tl2
19    | _                  -> assert false
20
21 let rec list_fold_left f map a = function
22    | []       -> f a
23    | hd :: tl -> 
24       let f a = list_fold_left f map a tl in
25       map f a hd
26
27 let rec list_rev_map_append f map ~tail = function
28       | []       -> f tail        
29       | hd :: tl ->
30          let f hd = list_rev_map_append f map ~tail:(hd :: tail) tl in
31          map f hd
32
33 let rec list_forall2 f map l1 l2 = match l1, l2 with
34    | [], []                 -> f true
35    | hd1 :: tl1, hd2 :: tl2 ->
36       let f b = if b then list_forall2 f map tl1 tl2 else f false in
37       map f hd1 hd2
38    | _                      -> f false
39
40 let list_rev_append f =
41    list_rev_map_append f (fun f t -> f t)
42
43 let list_rev_map =
44    list_rev_map_append ~tail:[]
45
46 let list_rev =
47    list_rev_append ~tail:[]
48
49 let list_fold_right f map l a =
50    let map f a m = map f m a in
51    list_rev (list_fold_left f map a) l
52
53 let list_map f =
54    list_rev_map (list_rev f)
55    
56 let list_iter f map l =
57    let map f () x = map f x in
58    list_fold_left f map () l
59
60 let rec list_fold_left2 f map a l1 l2 = match l1, l2 with
61    | [], []                 -> f a
62    | hd1 :: tl1, hd2 :: tl2 -> 
63       let f a = list_fold_left2 f map a tl1 tl2 in
64       map f a hd1 hd2
65    | _                      -> assert false