1 (* Title: Pure/term_xml.ML
4 XML data representation of lambda terms.
7 signature TERM_XML_OPS =
17 structure Encode: TERM_XML_OPS
18 structure Decode: TERM_XML_OPS
21 structure Term_XML: TERM_XML =
29 val sort = list string;
31 fun typ T = T |> variant
32 [fn Type (a, b) => ([a], list typ b),
33 fn TFree (a, b) => ([a], sort b),
34 fn TVar ((a, b), c) => ([a, int_atom b], sort c)];
36 fun term t = t |> variant
37 [fn Const (a, b) => ([a], typ b),
38 fn Free (a, b) => ([a], typ b),
39 fn Var ((a, b), c) => ([a, int_atom b], typ c),
40 fn Bound a => ([int_atom a], []),
41 fn Abs (a, b, c) => ([a], pair typ term (b, c)),
42 fn op $ a => ([], pair term term a)];
51 val sort = list string;
53 fun typ T = T |> variant
54 [fn ([a], b) => Type (a, list typ b),
55 fn ([a], b) => TFree (a, sort b),
56 fn ([a, b], c) => TVar ((a, int_atom b), sort c)];
58 fun term t = t |> variant
59 [fn ([a], b) => Const (a, typ b),
60 fn ([a], b) => Free (a, typ b),
61 fn ([a, b], c) => Var ((a, int_atom b), typ c),
62 fn ([a], []) => Bound (int_atom a),
63 fn ([a], b) => let val (c, d) = pair typ term b in Abs (a, c, d) end,
64 fn ([], a) => op $ (pair term term a)];