author | traytel |
Tue, 03 Mar 2015 19:08:04 +0100 | |
changeset 59580 | cbc38731d42f |
parent 54740 | 91f54d386680 |
child 61064 | 01b23bfb4947 |
permissions | -rw-r--r-- |
21476 | 1 |
(* Title: Pure/morphism.ML |
2 |
Author: Makarius |
|
3 |
||
4 |
Abstract morphisms on formal entities. |
|
5 |
*) |
|
6 |
||
7 |
infix 1 $> |
|
8 |
||
9 |
signature BASIC_MORPHISM = |
|
10 |
sig |
|
11 |
type morphism |
|
24031 | 12 |
type declaration = morphism -> Context.generic -> Context.generic |
21476 | 13 |
val $> : morphism * morphism -> morphism |
14 |
end |
|
15 |
||
16 |
signature MORPHISM = |
|
17 |
sig |
|
18 |
include BASIC_MORPHISM |
|
54740 | 19 |
exception MORPHISM of string * exn |
20 |
val pretty: morphism -> Pretty.T |
|
29581 | 21 |
val binding: morphism -> binding -> binding |
21476 | 22 |
val typ: morphism -> typ -> typ |
23 |
val term: morphism -> term -> term |
|
21521 | 24 |
val fact: morphism -> thm list -> thm list |
21476 | 25 |
val thm: morphism -> thm -> thm |
22235 | 26 |
val cterm: morphism -> cterm -> cterm |
54740 | 27 |
val morphism: string -> |
28 |
{binding: (binding -> binding) list, |
|
29 |
typ: (typ -> typ) list, |
|
30 |
term: (term -> term) list, |
|
31 |
fact: (thm list -> thm list) list} -> morphism |
|
32 |
val binding_morphism: string -> (binding -> binding) -> morphism |
|
33 |
val typ_morphism: string -> (typ -> typ) -> morphism |
|
34 |
val term_morphism: string -> (term -> term) -> morphism |
|
35 |
val fact_morphism: string -> (thm list -> thm list) -> morphism |
|
36 |
val thm_morphism: string -> (thm -> thm) -> morphism |
|
53087 | 37 |
val transfer_morphism: theory -> morphism |
21476 | 38 |
val identity: morphism |
22571
3f00e937d1c9
renamed comp to compose (avoid clash with Alice keywords);
wenzelm
parents:
22235
diff
changeset
|
39 |
val compose: morphism -> morphism -> morphism |
22670
c803b2696ada
added Morphism.transform/form (generic non-sense);
wenzelm
parents:
22571
diff
changeset
|
40 |
val transform: morphism -> (morphism -> 'a) -> morphism -> 'a |
c803b2696ada
added Morphism.transform/form (generic non-sense);
wenzelm
parents:
22571
diff
changeset
|
41 |
val form: (morphism -> 'a) -> 'a |
21476 | 42 |
end; |
43 |
||
44 |
structure Morphism: MORPHISM = |
|
45 |
struct |
|
46 |
||
54740 | 47 |
(* named functions *) |
48 |
||
49 |
type 'a funs = (string * ('a -> 'a)) list; |
|
50 |
||
51 |
exception MORPHISM of string * exn; |
|
52 |
||
53 |
fun app (name, f) x = f x |
|
54 |
handle exn => if Exn.is_interrupt exn then reraise exn else raise MORPHISM (name, exn); |
|
55 |
||
56 |
fun apply fs = fold_rev app fs; |
|
57 |
||
58 |
||
59 |
(* type morphism *) |
|
45289
25e9e7f527b4
slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents:
37216
diff
changeset
|
60 |
|
21476 | 61 |
datatype morphism = Morphism of |
54740 | 62 |
{names: string list, |
63 |
binding: binding funs, |
|
45289
25e9e7f527b4
slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents:
37216
diff
changeset
|
64 |
typ: typ funs, |
25e9e7f527b4
slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents:
37216
diff
changeset
|
65 |
term: term funs, |
25e9e7f527b4
slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents:
37216
diff
changeset
|
66 |
fact: thm list funs}; |
21476 | 67 |
|
24031 | 68 |
type declaration = morphism -> Context.generic -> Context.generic; |
69 |
||
54740 | 70 |
fun pretty (Morphism {names, ...}) = Pretty.enum ";" "{" "}" (map Pretty.str (rev names)); |
71 |
||
45289
25e9e7f527b4
slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents:
37216
diff
changeset
|
72 |
fun binding (Morphism {binding, ...}) = apply binding; |
25e9e7f527b4
slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents:
37216
diff
changeset
|
73 |
fun typ (Morphism {typ, ...}) = apply typ; |
25e9e7f527b4
slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents:
37216
diff
changeset
|
74 |
fun term (Morphism {term, ...}) = apply term; |
25e9e7f527b4
slightly more explicit/syntactic modelling of morphisms;
wenzelm
parents:
37216
diff
changeset
|
75 |
fun fact (Morphism {fact, ...}) = apply fact; |
21521 | 76 |
val thm = singleton o fact; |
22235 | 77 |
val cterm = Drule.cterm_rule o thm; |
21476 | 78 |
|
54740 | 79 |
|
80 |
fun morphism a {binding, typ, term, fact} = |
|
81 |
Morphism { |
|
82 |
names = if a = "" then [] else [a], |
|
83 |
binding = map (pair a) binding, |
|
84 |
typ = map (pair a) typ, |
|
85 |
term = map (pair a) term, |
|
86 |
fact = map (pair a) fact}; |
|
21476 | 87 |
|
54740 | 88 |
fun binding_morphism a binding = morphism a {binding = [binding], typ = [], term = [], fact = []}; |
89 |
fun typ_morphism a typ = morphism a {binding = [], typ = [typ], term = [], fact = []}; |
|
90 |
fun term_morphism a term = morphism a {binding = [], typ = [], term = [term], fact = []}; |
|
91 |
fun fact_morphism a fact = morphism a {binding = [], typ = [], term = [], fact = [fact]}; |
|
92 |
fun thm_morphism a thm = morphism a {binding = [], typ = [], term = [], fact = [map thm]}; |
|
93 |
val transfer_morphism = thm_morphism "transfer" o Thm.transfer; |
|
21492 | 94 |
|
54740 | 95 |
val identity = morphism "" {binding = [], typ = [], term = [], fact = []}; |
96 |
||
97 |
||
98 |
(* morphism combinators *) |
|
21492 | 99 |
|
22571
3f00e937d1c9
renamed comp to compose (avoid clash with Alice keywords);
wenzelm
parents:
22235
diff
changeset
|
100 |
fun compose |
54740 | 101 |
(Morphism {names = names1, binding = binding1, typ = typ1, term = term1, fact = fact1}) |
102 |
(Morphism {names = names2, binding = binding2, typ = typ2, term = term2, fact = fact2}) = |
|
103 |
Morphism { |
|
104 |
names = names1 @ names2, |
|
105 |
binding = binding1 @ binding2, |
|
106 |
typ = typ1 @ typ2, |
|
107 |
term = term1 @ term2, |
|
108 |
fact = fact1 @ fact2}; |
|
21476 | 109 |
|
22571
3f00e937d1c9
renamed comp to compose (avoid clash with Alice keywords);
wenzelm
parents:
22235
diff
changeset
|
110 |
fun phi1 $> phi2 = compose phi2 phi1; |
21476 | 111 |
|
22670
c803b2696ada
added Morphism.transform/form (generic non-sense);
wenzelm
parents:
22571
diff
changeset
|
112 |
fun transform phi f = fn psi => f (phi $> psi); |
c803b2696ada
added Morphism.transform/form (generic non-sense);
wenzelm
parents:
22571
diff
changeset
|
113 |
fun form f = f identity; |
c803b2696ada
added Morphism.transform/form (generic non-sense);
wenzelm
parents:
22571
diff
changeset
|
114 |
|
21476 | 115 |
end; |
116 |
||
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
29605
diff
changeset
|
117 |
structure Basic_Morphism: BASIC_MORPHISM = Morphism; |
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
29605
diff
changeset
|
118 |
open Basic_Morphism; |