src/Pure/morphism.ML
author wenzelm
Mon Aug 19 20:37:36 2013 +0200 (2013-08-19)
changeset 53087 5a1dcda7967c
parent 45289 25e9e7f527b4
child 54740 91f54d386680
permissions -rw-r--r--
tuned signature;
wenzelm@21476
     1
(*  Title:      Pure/morphism.ML
wenzelm@21476
     2
    Author:     Makarius
wenzelm@21476
     3
wenzelm@21476
     4
Abstract morphisms on formal entities.
wenzelm@21476
     5
*)
wenzelm@21476
     6
wenzelm@21476
     7
infix 1 $>
wenzelm@21476
     8
wenzelm@21476
     9
signature BASIC_MORPHISM =
wenzelm@21476
    10
sig
wenzelm@21476
    11
  type morphism
wenzelm@24031
    12
  type declaration = morphism -> Context.generic -> Context.generic
wenzelm@21476
    13
  val $> : morphism * morphism -> morphism
wenzelm@21476
    14
end
wenzelm@21476
    15
wenzelm@21476
    16
signature MORPHISM =
wenzelm@21476
    17
sig
wenzelm@21476
    18
  include BASIC_MORPHISM
wenzelm@45289
    19
  type 'a funs = ('a -> 'a) list
haftmann@29581
    20
  val binding: morphism -> binding -> binding
wenzelm@21476
    21
  val typ: morphism -> typ -> typ
wenzelm@21476
    22
  val term: morphism -> term -> term
wenzelm@21521
    23
  val fact: morphism -> thm list -> thm list
wenzelm@21476
    24
  val thm: morphism -> thm -> thm
wenzelm@22235
    25
  val cterm: morphism -> cterm -> cterm
wenzelm@21476
    26
  val morphism:
wenzelm@45289
    27
   {binding: binding funs,
wenzelm@45289
    28
    typ: typ funs,
wenzelm@45289
    29
    term: term funs,
wenzelm@45289
    30
    fact: thm list funs} -> morphism
haftmann@29581
    31
  val binding_morphism: (binding -> binding) -> morphism
wenzelm@21492
    32
  val typ_morphism: (typ -> typ) -> morphism
wenzelm@21492
    33
  val term_morphism: (term -> term) -> morphism
wenzelm@21521
    34
  val fact_morphism: (thm list -> thm list) -> morphism
wenzelm@21492
    35
  val thm_morphism: (thm -> thm) -> morphism
wenzelm@53087
    36
  val transfer_morphism: theory -> morphism
wenzelm@21476
    37
  val identity: morphism
wenzelm@22571
    38
  val compose: morphism -> morphism -> morphism
wenzelm@22670
    39
  val transform: morphism -> (morphism -> 'a) -> morphism -> 'a
wenzelm@22670
    40
  val form: (morphism -> 'a) -> 'a
wenzelm@21476
    41
end;
wenzelm@21476
    42
wenzelm@21476
    43
structure Morphism: MORPHISM =
wenzelm@21476
    44
struct
wenzelm@21476
    45
wenzelm@45289
    46
type 'a funs = ('a -> 'a) list;
wenzelm@45289
    47
fun apply fs = fold_rev (fn f => fn x => f x) fs;
wenzelm@45289
    48
wenzelm@21476
    49
datatype morphism = Morphism of
wenzelm@45289
    50
 {binding: binding funs,
wenzelm@45289
    51
  typ: typ funs,
wenzelm@45289
    52
  term: term funs,
wenzelm@45289
    53
  fact: thm list funs};
wenzelm@21476
    54
wenzelm@24031
    55
type declaration = morphism -> Context.generic -> Context.generic;
wenzelm@24031
    56
wenzelm@45289
    57
fun binding (Morphism {binding, ...}) = apply binding;
wenzelm@45289
    58
fun typ (Morphism {typ, ...}) = apply typ;
wenzelm@45289
    59
fun term (Morphism {term, ...}) = apply term;
wenzelm@45289
    60
fun fact (Morphism {fact, ...}) = apply fact;
wenzelm@21521
    61
val thm = singleton o fact;
wenzelm@22235
    62
val cterm = Drule.cterm_rule o thm;
wenzelm@21476
    63
wenzelm@21476
    64
val morphism = Morphism;
wenzelm@21476
    65
wenzelm@45289
    66
fun binding_morphism binding = morphism {binding = [binding], typ = [], term = [], fact = []};
wenzelm@45289
    67
fun typ_morphism typ = morphism {binding = [], typ = [typ], term = [], fact = []};
wenzelm@45289
    68
fun term_morphism term = morphism {binding = [], typ = [], term = [term], fact = []};
wenzelm@45289
    69
fun fact_morphism fact = morphism {binding = [], typ = [], term = [], fact = [fact]};
wenzelm@45289
    70
fun thm_morphism thm = morphism {binding = [], typ = [], term = [], fact = [map thm]};
wenzelm@53087
    71
val transfer_morphism = thm_morphism o Thm.transfer;
wenzelm@21492
    72
wenzelm@45289
    73
val identity = morphism {binding = [], typ = [], term = [], fact = []};
wenzelm@21492
    74
wenzelm@22571
    75
fun compose
wenzelm@29605
    76
    (Morphism {binding = binding1, typ = typ1, term = term1, fact = fact1})
wenzelm@29605
    77
    (Morphism {binding = binding2, typ = typ2, term = term2, fact = fact2}) =
wenzelm@45289
    78
  morphism {binding = binding1 @ binding2, typ = typ1 @ typ2,
wenzelm@45289
    79
    term = term1 @ term2, fact = fact1 @ fact2};
wenzelm@21476
    80
wenzelm@22571
    81
fun phi1 $> phi2 = compose phi2 phi1;
wenzelm@21476
    82
wenzelm@22670
    83
fun transform phi f = fn psi => f (phi $> psi);
wenzelm@22670
    84
fun form f = f identity;
wenzelm@22670
    85
wenzelm@21476
    86
end;
wenzelm@21476
    87
wenzelm@37216
    88
structure Basic_Morphism: BASIC_MORPHISM = Morphism;
wenzelm@37216
    89
open Basic_Morphism;