]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/common/hierarchy.ml
Additional contribs.
[helm.git] / helm / software / lambda-delta / common / hierarchy.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 module H = Hashtbl
13 module S = Scanf
14 module C = Cps
15
16 type graph = string * (int -> int)
17
18 let sorts = 2
19 let sort = H.create sorts
20
21 (* Internal functions *******************************************************)
22
23 let set_sort h s =
24    H.add sort h s; succ h
25
26 (* Interface functions ******************************************************)
27
28 let set_sorts ss i =   
29    List.fold_left set_sort i ss
30
31 let get_sort err f h =
32    try f (H.find sort h) with Not_found -> err ()
33
34 let string_of_graph (s, _) = s
35
36 let apply (_, g) h = (g h)
37
38 let graph_of_string err f s =
39    try 
40       let x = S.sscanf s "Z%u" C.start in 
41       if x > 0 then f (s, fun h -> x + h) else err ()
42    with
43       S.Scan_failure _ | Failure _ | End_of_file -> err ()