summary |
shortlog |
changelog |
graph |
tags |
branches |
files |
changeset |
file |
revisions |
annotate |
diff |
raw

src/Pure/morphism.ML

author | wenzelm |

Fri Oct 07 21:16:48 2016 +0200 (2016-10-07) | |

changeset 64092 | 95469c544b82 |

parent 62819 | d3ff367a16a0 |

child 67650 | 5e4f9a0ffea5 |

permissions | -rw-r--r-- |

accept obscure timezone used in 2011;

1 (* Title: Pure/morphism.ML

2 Author: Makarius

4 Abstract morphisms on formal entities.

5 *)

7 infix 1 $>

9 signature BASIC_MORPHISM =

10 sig

11 type morphism

12 type declaration = morphism -> Context.generic -> Context.generic

13 val $> : morphism * morphism -> morphism

14 end

16 signature MORPHISM =

17 sig

18 include BASIC_MORPHISM

19 exception MORPHISM of string * exn

20 val pretty: morphism -> Pretty.T

21 val binding: morphism -> binding -> binding

22 val typ: morphism -> typ -> typ

23 val term: morphism -> term -> term

24 val fact: morphism -> thm list -> thm list

25 val thm: morphism -> thm -> thm

26 val cterm: morphism -> cterm -> cterm

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

37 val transfer_morphism: theory -> morphism

38 val trim_context_morphism: morphism

39 val identity: morphism

40 val compose: morphism -> morphism -> morphism

41 val transform: morphism -> (morphism -> 'a) -> morphism -> 'a

42 val form: (morphism -> 'a) -> 'a

43 end;

45 structure Morphism: MORPHISM =

46 struct

48 (* named functions *)

50 type 'a funs = (string * ('a -> 'a)) list;

52 exception MORPHISM of string * exn;

54 fun app (name, f) x = f x

55 handle exn =>

56 if Exn.is_interrupt exn then Exn.reraise exn else raise MORPHISM (name, exn);

58 fun apply fs = fold_rev app fs;

61 (* type morphism *)

63 datatype morphism = Morphism of

64 {names: string list,

65 binding: binding funs,

66 typ: typ funs,

67 term: term funs,

68 fact: thm list funs};

70 type declaration = morphism -> Context.generic -> Context.generic;

72 fun pretty (Morphism {names, ...}) = Pretty.enum ";" "{" "}" (map Pretty.str (rev names));

74 val _ = ML_system_pp (fn _ => fn _ => Pretty.to_polyml o pretty);

76 fun binding (Morphism {binding, ...}) = apply binding;

77 fun typ (Morphism {typ, ...}) = apply typ;

78 fun term (Morphism {term, ...}) = apply term;

79 fun fact (Morphism {fact, ...}) = apply fact;

80 val thm = singleton o fact;

81 val cterm = Drule.cterm_rule o thm;

84 fun morphism a {binding, typ, term, fact} =

85 Morphism {

86 names = if a = "" then [] else [a],

87 binding = map (pair a) binding,

88 typ = map (pair a) typ,

89 term = map (pair a) term,

90 fact = map (pair a) fact};

92 fun binding_morphism a binding = morphism a {binding = [binding], typ = [], term = [], fact = []};

93 fun typ_morphism a typ = morphism a {binding = [], typ = [typ], term = [], fact = []};

94 fun term_morphism a term = morphism a {binding = [], typ = [], term = [term], fact = []};

95 fun fact_morphism a fact = morphism a {binding = [], typ = [], term = [], fact = [fact]};

96 fun thm_morphism a thm = morphism a {binding = [], typ = [], term = [], fact = [map thm]};

97 val transfer_morphism = thm_morphism "transfer" o Thm.transfer;

98 val trim_context_morphism = thm_morphism "trim_context" Thm.trim_context;

100 val identity = morphism "" {binding = [], typ = [], term = [], fact = []};

103 (* morphism combinators *)

105 fun compose

106 (Morphism {names = names1, binding = binding1, typ = typ1, term = term1, fact = fact1})

107 (Morphism {names = names2, binding = binding2, typ = typ2, term = term2, fact = fact2}) =

108 Morphism {

109 names = names1 @ names2,

110 binding = binding1 @ binding2,

111 typ = typ1 @ typ2,

112 term = term1 @ term2,

113 fact = fact1 @ fact2};

115 fun phi1 $> phi2 = compose phi2 phi1;

117 fun transform phi f = fn psi => f (phi $> psi);

118 fun form f = f identity;

120 end;

122 structure Basic_Morphism: BASIC_MORPHISM = Morphism;

123 open Basic_Morphism;