src/Pure/morphism.ML
author wenzelm
Fri Oct 28 15:38:41 2011 +0200 (2011-10-28)
changeset 45289 25e9e7f527b4
parent 37216 3165bc303f66
child 53087 5a1dcda7967c
permissions -rw-r--r--
slightly more explicit/syntactic modelling of morphisms;
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@21476
    36
  val identity: morphism
wenzelm@22571
    37
  val compose: morphism -> morphism -> morphism
wenzelm@22670
    38
  val transform: morphism -> (morphism -> 'a) -> morphism -> 'a
wenzelm@22670
    39
  val form: (morphism -> 'a) -> 'a
wenzelm@21476
    40
end;
wenzelm@21476
    41
wenzelm@21476
    42
structure Morphism: MORPHISM =
wenzelm@21476
    43
struct
wenzelm@21476
    44
wenzelm@45289
    45
type 'a funs = ('a -> 'a) list;
wenzelm@45289
    46
fun apply fs = fold_rev (fn f => fn x => f x) fs;
wenzelm@45289
    47
wenzelm@21476
    48
datatype morphism = Morphism of
wenzelm@45289
    49
 {binding: binding funs,
wenzelm@45289
    50
  typ: typ funs,
wenzelm@45289
    51
  term: term funs,
wenzelm@45289
    52
  fact: thm list funs};
wenzelm@21476
    53
wenzelm@24031
    54
type declaration = morphism -> Context.generic -> Context.generic;
wenzelm@24031
    55
wenzelm@45289
    56
fun binding (Morphism {binding, ...}) = apply binding;
wenzelm@45289
    57
fun typ (Morphism {typ, ...}) = apply typ;
wenzelm@45289
    58
fun term (Morphism {term, ...}) = apply term;
wenzelm@45289
    59
fun fact (Morphism {fact, ...}) = apply fact;
wenzelm@21521
    60
val thm = singleton o fact;
wenzelm@22235
    61
val cterm = Drule.cterm_rule o thm;
wenzelm@21476
    62
wenzelm@21476
    63
val morphism = Morphism;
wenzelm@21476
    64
wenzelm@45289
    65
fun binding_morphism binding = morphism {binding = [binding], typ = [], term = [], fact = []};
wenzelm@45289
    66
fun typ_morphism typ = morphism {binding = [], typ = [typ], term = [], fact = []};
wenzelm@45289
    67
fun term_morphism term = morphism {binding = [], typ = [], term = [term], fact = []};
wenzelm@45289
    68
fun fact_morphism fact = morphism {binding = [], typ = [], term = [], fact = [fact]};
wenzelm@45289
    69
fun thm_morphism thm = morphism {binding = [], typ = [], term = [], fact = [map thm]};
wenzelm@21492
    70
wenzelm@45289
    71
val identity = morphism {binding = [], typ = [], term = [], fact = []};
wenzelm@21492
    72
wenzelm@22571
    73
fun compose
wenzelm@29605
    74
    (Morphism {binding = binding1, typ = typ1, term = term1, fact = fact1})
wenzelm@29605
    75
    (Morphism {binding = binding2, typ = typ2, term = term2, fact = fact2}) =
wenzelm@45289
    76
  morphism {binding = binding1 @ binding2, typ = typ1 @ typ2,
wenzelm@45289
    77
    term = term1 @ term2, fact = fact1 @ fact2};
wenzelm@21476
    78
wenzelm@22571
    79
fun phi1 $> phi2 = compose phi2 phi1;
wenzelm@21476
    80
wenzelm@22670
    81
fun transform phi f = fn psi => f (phi $> psi);
wenzelm@22670
    82
fun form f = f identity;
wenzelm@22670
    83
wenzelm@21476
    84
end;
wenzelm@21476
    85
wenzelm@37216
    86
structure Basic_Morphism: BASIC_MORPHISM = Morphism;
wenzelm@37216
    87
open Basic_Morphism;