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

src/Pure/morphism.ML

author | blanchet |

Mon May 19 23:43:53 2014 +0200 (2014-05-19) | |

changeset 57008 | 10f68b83b474 |

parent 54740 | 91f54d386680 |

child 61064 | 01b23bfb4947 |

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

use E 1.8's auto scheduler option

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 identity: morphism

39 val compose: morphism -> morphism -> morphism

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

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

42 end;

44 structure Morphism: MORPHISM =

45 struct

47 (* named functions *)

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

51 exception MORPHISM of string * exn;

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

54 handle exn => if Exn.is_interrupt exn then reraise exn else raise MORPHISM (name, exn);

56 fun apply fs = fold_rev app fs;

59 (* type morphism *)

61 datatype morphism = Morphism of

62 {names: string list,

63 binding: binding funs,

64 typ: typ funs,

65 term: term funs,

66 fact: thm list funs};

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

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

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

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

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

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

76 val thm = singleton o fact;

77 val cterm = Drule.cterm_rule o thm;

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};

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;

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

98 (* morphism combinators *)

100 fun compose

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};

110 fun phi1 $> phi2 = compose phi2 phi1;

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

113 fun form f = f identity;

115 end;

117 structure Basic_Morphism: BASIC_MORPHISM = Morphism;

118 open Basic_Morphism;