]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/lib/cps.ml
2e8b2c7155715c14d106bad53edd72bb21c11e0a
[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 forall2 f map l1 l2 = match l1, l2 with
34    | [], []                 -> f true
35    | hd1 :: tl1, hd2 :: tl2 ->
36       let f b = if b then 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_map f =
50    list_rev_map (list_rev f)
51    
52 let list_iter f map l =
53    let map f () x = map f x in
54    list_fold_left f map () l