author | wenzelm |
Tue, 12 Jul 2011 17:53:06 +0200 | |
changeset 43778 | ce9189450447 |
parent 43767 | e0219ef7f84c |
child 43779 | 47bec02c6762 |
permissions | -rw-r--r-- |
43730 | 1 |
/* Title: Pure/term.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Lambda terms with XML data representation. |
|
5 |
||
6 |
Note: Isabelle/ML is the primary environment for logical operations. |
|
7 |
*/ |
|
8 |
||
9 |
package isabelle |
|
10 |
||
11 |
||
12 |
object Term |
|
13 |
{ |
|
14 |
/* basic type definitions */ |
|
15 |
||
16 |
type Indexname = (String, Int) |
|
17 |
||
18 |
type Sort = List[String] |
|
19 |
val dummyS: Sort = List("") |
|
20 |
||
21 |
sealed abstract class Typ |
|
22 |
case class Type(name: String, args: List[Typ] = Nil) extends Typ |
|
23 |
case class TFree(name: String, sort: Sort = dummyS) extends Typ |
|
24 |
case class TVar(name: Indexname, sort: Sort = dummyS) extends Typ |
|
25 |
val dummyT = Type("dummy") |
|
26 |
||
27 |
sealed abstract class Term |
|
28 |
case class Const(name: String, typ: Typ = dummyT) extends Term |
|
29 |
case class Free(name: String, typ: Typ = dummyT) extends Term |
|
30 |
case class Var(name: Indexname, typ: Typ = dummyT) extends Term |
|
31 |
case class Bound(index: Int) extends Term |
|
32 |
case class Abs(name: String, typ: Typ = dummyT, body: Term) extends Term |
|
33 |
case class App(fun: Term, arg: Term) extends Term |
|
43731
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
34 |
} |
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
35 |
|
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
36 |
|
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
37 |
object Term_XML |
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
38 |
{ |
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
39 |
import Term._ |
43730 | 40 |
|
41 |
||
42 |
/* XML data representation */ |
|
43 |
||
43731
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
44 |
object Encode |
43730 | 45 |
{ |
43767 | 46 |
import XML.Encode._ |
43730 | 47 |
|
43731
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
48 |
val sort: T[Sort] = list(string) |
43730 | 49 |
|
43731
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
50 |
def typ: T[Typ] = |
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
51 |
variant[Typ](List( |
43778
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
52 |
{ case Type(a, b) => (List(a), list(typ)(b)) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
53 |
{ case TFree(a, b) => (List(a), sort(b)) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
54 |
{ case TVar((a, b), c) => (List(a, int_atom(b)), sort(c)) })) |
43730 | 55 |
|
43731
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
56 |
def term: T[Term] = |
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
57 |
variant[Term](List( |
43778
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
58 |
{ case Const(a, b) => (List(a), typ(b)) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
59 |
{ case Free(a, b) => (List(a), typ(b)) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
60 |
{ case Var((a, b), c) => (List(a, int_atom(b)), typ(c)) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
61 |
{ case Bound(a) => (List(int_atom(a)), Nil) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
62 |
{ case Abs(a, b, c) => (List(a), pair(typ, term)(b, c)) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
63 |
{ case App(a, b) => (Nil, pair(term, term)(a, b)) })) |
43731
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
64 |
} |
43730 | 65 |
|
43731
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
66 |
object Decode |
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
67 |
{ |
43767 | 68 |
import XML.Decode._ |
43730 | 69 |
|
43731
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
70 |
val sort: T[Sort] = list(string) |
43730 | 71 |
|
43731
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
72 |
def typ: T[Typ] = |
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
73 |
variant[Typ](List( |
43778
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
74 |
{ case (List(a), b) => Type(a, list(typ)(b)) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
75 |
{ case (List(a), b) => TFree(a, sort(b)) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
76 |
{ case (List(a, b), c) => TVar((a, int_atom(b)), sort(c)) })) |
43730 | 77 |
|
43731
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
78 |
def term: T[Term] = |
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
79 |
variant[Term](List( |
43778
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
80 |
{ case (List(a), b) => Const(a, typ(b)) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
81 |
{ case (List(a), b) => Free(a, typ(b)) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
82 |
{ case (List(a, b), c) => Var((a, int_atom(b)), typ(c)) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
83 |
{ case (List(a), Nil) => Bound(int_atom(a)) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
84 |
{ case (List(a), b) => val (c, d) = pair(typ, term)(b); Abs(a, c, d) }, |
ce9189450447
more compact representation of XML data (notably sort/typ/term), using properties as vector of atomic values;
wenzelm
parents:
43767
diff
changeset
|
85 |
{ case (Nil, a) => val (b, c) = pair(term, term)(a); App(b, c) })) |
43730 | 86 |
} |
87 |
} |