src/Pure/morphism.ML
author wenzelm
Sat Dec 13 15:00:39 2008 +0100 (2008-12-13)
changeset 29091 b81fe045e799
parent 28965 1de908189869
child 29581 b3b33e0298eb
permissions -rw-r--r--
Context.display_names;
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
haftmann@28965
    19
  val var: morphism -> Binding.T * mixfix -> Binding.T * mixfix
haftmann@28965
    20
  val binding: morphism -> Binding.T -> Binding.T
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:
haftmann@28965
    27
   {binding: Binding.T -> Binding.T,
haftmann@28965
    28
    var: Binding.T * mixfix -> Binding.T * mixfix,
wenzelm@21476
    29
    typ: typ -> typ,
wenzelm@21476
    30
    term: term -> term,
wenzelm@21521
    31
    fact: thm list -> thm list} -> morphism
haftmann@28965
    32
  val binding_morphism: (Binding.T -> Binding.T) -> morphism
haftmann@28965
    33
  val var_morphism: (Binding.T * mixfix -> Binding.T * mixfix) -> morphism
wenzelm@21492
    34
  val typ_morphism: (typ -> typ) -> morphism
wenzelm@21492
    35
  val term_morphism: (term -> term) -> morphism
wenzelm@21521
    36
  val fact_morphism: (thm list -> thm list) -> morphism
wenzelm@21492
    37
  val thm_morphism: (thm -> thm) -> morphism
wenzelm@21476
    38
  val identity: morphism
wenzelm@22571
    39
  val compose: morphism -> morphism -> morphism
wenzelm@22670
    40
  val transform: morphism -> (morphism -> 'a) -> morphism -> 'a
wenzelm@22670
    41
  val form: (morphism -> 'a) -> 'a
wenzelm@21476
    42
end;
wenzelm@21476
    43
wenzelm@21476
    44
structure Morphism: MORPHISM =
wenzelm@21476
    45
struct
wenzelm@21476
    46
wenzelm@21476
    47
datatype morphism = Morphism of
haftmann@28965
    48
 {binding: Binding.T -> Binding.T,
haftmann@28965
    49
  var: Binding.T * mixfix -> Binding.T * mixfix,
wenzelm@21476
    50
  typ: typ -> typ,
wenzelm@21476
    51
  term: term -> term,
wenzelm@21521
    52
  fact: thm list -> thm list};
wenzelm@21476
    53
wenzelm@24031
    54
type declaration = morphism -> Context.generic -> Context.generic;
wenzelm@24031
    55
haftmann@28965
    56
fun binding (Morphism {binding, ...}) = binding;
wenzelm@21476
    57
fun var (Morphism {var, ...}) = var;
wenzelm@21476
    58
fun typ (Morphism {typ, ...}) = typ;
wenzelm@21476
    59
fun term (Morphism {term, ...}) = term;
wenzelm@21521
    60
fun fact (Morphism {fact, ...}) = 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
haftmann@28965
    66
fun binding_morphism binding = morphism {binding = binding, var = I, typ = I, term = I, fact = I};
haftmann@28965
    67
fun var_morphism var = morphism {binding = I, var = var, typ = I, term = I, fact = I};
haftmann@28965
    68
fun typ_morphism typ = morphism {binding = I, var = I, typ = typ, term = I, fact = I};
haftmann@28965
    69
fun term_morphism term = morphism {binding = I, var = I, typ = I, term = term, fact = I};
haftmann@28965
    70
fun fact_morphism fact = morphism {binding = I, var = I, typ = I, term = I, fact = fact};
haftmann@28965
    71
fun thm_morphism thm = morphism {binding = I, var = I, typ = I, term = I, fact = map thm};
wenzelm@21492
    72
haftmann@28965
    73
val identity = morphism {binding = I, var = I, typ = I, term = I, fact = I};
wenzelm@21492
    74
wenzelm@22571
    75
fun compose
haftmann@28965
    76
    (Morphism {binding = binding1, var = var1, typ = typ1, term = term1, fact = fact1})
haftmann@28965
    77
    (Morphism {binding = binding2, var = var2, typ = typ2, term = term2, fact = fact2}) =
haftmann@28965
    78
  morphism {binding = binding1 o binding2, var = var1 o var2,
wenzelm@21521
    79
    typ = typ1 o typ2, term = term1 o term2, fact = fact1 o 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@21476
    88
structure BasicMorphism: BASIC_MORPHISM = Morphism;
wenzelm@21476
    89
open BasicMorphism;