]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/lib/cps.ml
e42faba498aa4b0806e4264f0b0099d67f9f6e30
[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 err _ = assert false
13
14 let start x = x
15
16 let id f x = f x
17
18 let rec list_sub_strict f l1 l2 = match l1, l2 with
19    | _, []              -> f l1
20    | _ :: tl1, _ :: tl2 -> list_sub_strict f tl1 tl2
21    | _                  -> assert false
22
23 let rec list_fold_left f map a = function
24    | []       -> f a
25    | hd :: tl -> 
26       let f a = list_fold_left f map a tl in
27       map f a hd
28
29 let rec list_rev_map_append f map ~tail = function
30       | []       -> f tail        
31       | hd :: tl ->
32          let f hd = list_rev_map_append f map ~tail:(hd :: tail) tl in
33          map f hd
34
35 let rec list_forall2 f map l1 l2 = match l1, l2 with
36    | [], []                 -> f true
37    | hd1 :: tl1, hd2 :: tl2 ->
38       let f b = if b then list_forall2 f map tl1 tl2 else f false in
39       map f hd1 hd2
40    | _                      -> f false
41
42 let list_rev_append f =
43    list_rev_map_append f (fun f t -> f t)
44
45 let list_rev_map =
46    list_rev_map_append ~tail:[]
47
48 let list_rev =
49    list_rev_append ~tail:[]
50
51 let list_fold_right f map l a =
52    let map f a m = map f m a in
53    list_rev (list_fold_left f map a) l
54
55 let list_map f =
56    list_rev_map (list_rev f)
57    
58 let list_iter f map l =
59    let map f () x = map f x in
60    list_fold_left f map () l
61
62 let rec list_fold_left2 f map a l1 l2 = match l1, l2 with
63    | [], []                 -> f a
64    | hd1 :: tl1, hd2 :: tl2 -> 
65       let f a = list_fold_left2 f map a tl1 tl2 in
66       map f a hd1 hd2
67    | _                      -> assert false
68
69 let list_iter2 f map l1 l2 =
70    let map f () x1 x2 = map f x1 x2 in
71    list_fold_left2 f map () l1 l2
72
73 let rec list_mem ?(eq=(=)) a = function
74    | []                   -> false
75    | hd :: _ when eq a hd -> true
76    | _ :: tl              -> list_mem ~eq a tl