|
1 (* Title: Pure/term_xml.ML |
|
2 Author: Makarius |
|
3 |
|
4 XML data representation of lambda terms. |
|
5 *) |
|
6 |
|
7 signature TERM_XML_OPS = |
|
8 sig |
|
9 type 'a T |
|
10 val indexname: indexname T |
|
11 val class: class T |
|
12 val sort: sort T |
|
13 val typ: typ T |
|
14 val term: term T |
|
15 end |
|
16 |
|
17 signature TERM_XML = |
|
18 sig |
|
19 structure Make: TERM_XML_OPS where type 'a T = 'a XML_Data.Make.T |
|
20 structure Dest: TERM_XML_OPS where type 'a T = 'a XML_Data.Dest.T |
|
21 end; |
|
22 |
|
23 structure Term_XML: TERM_XML = |
|
24 struct |
|
25 |
|
26 (* make *) |
|
27 |
|
28 structure Make = |
|
29 struct |
|
30 |
|
31 open XML_Data.Make; |
|
32 |
|
33 val indexname = pair string int; |
|
34 val class = string; |
|
35 val sort = list class; |
|
36 |
|
37 fun typ T = T |> variant |
|
38 [fn Type x => pair string (list typ) x, |
|
39 fn TFree x => pair string sort x, |
|
40 fn TVar x => pair indexname sort x]; |
|
41 |
|
42 fun term t = t |> variant |
|
43 [fn Const x => pair string typ x, |
|
44 fn Free x => pair string typ x, |
|
45 fn Var x => pair indexname typ x, |
|
46 fn Bound x => int x, |
|
47 fn Abs x => triple string typ term x, |
|
48 fn op $ x => pair term term x]; |
|
49 |
|
50 end; |
|
51 |
|
52 |
|
53 (* dest *) |
|
54 |
|
55 structure Dest = |
|
56 struct |
|
57 |
|
58 open XML_Data.Dest; |
|
59 |
|
60 val indexname = pair string int; |
|
61 val class = string; |
|
62 val sort = list class; |
|
63 |
|
64 fun typ T = T |> variant |
|
65 [Type o pair string (list typ), |
|
66 TFree o pair string sort, |
|
67 TVar o pair indexname sort]; |
|
68 |
|
69 fun term t = t |> variant |
|
70 [Const o pair string typ, |
|
71 Free o pair string typ, |
|
72 Var o pair indexname typ, |
|
73 Bound o int, |
|
74 Abs o triple string typ term, |
|
75 op $ o pair term term]; |
|
76 |
|
77 end; |
|
78 |
|
79 end; |