/[svn]/types/sequence.ml
ViewVC logotype

Contents of /types/sequence.ml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 222 - (show annotations)
Tue Jul 10 17:15:58 2007 UTC (5 years, 10 months ago) by abate
File size: 1703 byte(s)
[r2003-03-07 17:31:04 by cvscast] Empty log message

Original author: cvscast
Date: 2003-03-07 17:31:05+00:00
1 let nil_atom = Atoms.mk "nil"
2 let nil_type = Types.atom (Atoms.atom nil_atom)
3
4 let decompose t =
5 (Types.Atom.has_atom t nil_atom,
6 Types.Product.get t)
7
8 module V = Types.Positive
9 module H = Types.DescrMap
10
11 let mapping f t queue =
12 let memo = ref H.empty in
13 let rec aux t =
14 try H.find t !memo
15 with Not_found ->
16 let v = V.forward () in
17 memo := H.add t v !memo;
18 let (has_nil,rect) = decompose t in
19 let l = List.map (fun (t1,t2) -> f t1 (aux t2)) rect in
20 let l = if has_nil then queue :: l else l in
21 V.define v (V.cup l);
22 v
23 in
24 aux t
25
26
27 let aux_concat = mapping (fun t v -> V.times (V.ty t) v)
28 let aux_flatten t = mapping aux_concat t (V.ty nil_type)
29 let aux_map f t = mapping (fun t v -> V.times (V.ty (f t)) v) t (V.ty nil_type)
30
31 let solve x = Types.descr (V.solve x)
32
33 let concat t1 t2 = solve (aux_concat t1 (V.ty t2))
34 let flatten t = solve (aux_flatten t)
35 let map f t = solve (aux_map f t)
36
37 let recurs f =
38 let n = Types.make () in
39 Types.define n (f n);
40 Types.internalize n
41
42 let star_node t = recurs (fun n -> Types.cup nil_type (Types.times t n ))
43
44 let any_node = star_node (Types.cons Types.any)
45 let any = Types.descr any_node
46 let seqseq = Types.descr (star_node any_node)
47
48 let star t = Types.descr (star_node (Types.cons t))
49 let plus t = let t = Types.cons t in Types.times t (star_node t)
50 let string = star (Types.Char.any)
51
52 let approx t =
53 let memo = ref H.empty in
54 let res = ref Types.empty in
55 let rec aux t =
56 try H.find t !memo
57 with Not_found ->
58 memo := H.add t () !memo;
59 let rect = Types.Product.get t in
60 List.iter (fun (t1,t2) -> res := Types.cup t1 !res; aux t2) rect;
61 in
62 aux t;
63 !res
64
65

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5