src/Pure/morphism.ML
author haftmann
Thu Oct 22 13:48:06 2009 +0200 (2009-10-22)
changeset 33063 4d462963a7db
parent 29605 f2924219125e
child 37216 3165bc303f66
permissions -rw-r--r--
map_range (and map_index) combinator
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@29581
    19
  val binding: morphism -> binding -> binding
wenzelm@21476
    20
  val typ: morphism -> typ -> typ
wenzelm@21476
    21
  val term: morphism -> term -> term
wenzelm@21521
    22
  val fact: morphism -> thm list -> thm list
wenzelm@21476
    23
  val thm: morphism -> thm -> thm
wenzelm@22235
    24
  val cterm: morphism -> cterm -> cterm
wenzelm@21476
    25
  val morphism:
haftmann@29581
    26
   {binding: binding -> binding,
wenzelm@21476
    27
    typ: typ -> typ,
wenzelm@21476
    28
    term: term -> term,
wenzelm@21521
    29
    fact: thm list -> thm list} -> morphism
haftmann@29581
    30
  val binding_morphism: (binding -> binding) -> morphism
wenzelm@21492
    31
  val typ_morphism: (typ -> typ) -> morphism
wenzelm@21492
    32
  val term_morphism: (term -> term) -> morphism
wenzelm@21521
    33
  val fact_morphism: (thm list -> thm list) -> morphism
wenzelm@21492
    34
  val thm_morphism: (thm -> thm) -> morphism
wenzelm@21476
    35
  val identity: morphism
wenzelm@22571
    36
  val compose: morphism -> morphism -> morphism
wenzelm@22670
    37
  val transform: morphism -> (morphism -> 'a) -> morphism -> 'a
wenzelm@22670
    38
  val form: (morphism -> 'a) -> 'a
wenzelm@21476
    39
end;
wenzelm@21476
    40
wenzelm@21476
    41
structure Morphism: MORPHISM =
wenzelm@21476
    42
struct
wenzelm@21476
    43
wenzelm@21476
    44
datatype morphism = Morphism of
haftmann@29581
    45
 {binding: binding -> binding,
wenzelm@21476
    46
  typ: typ -> typ,
wenzelm@21476
    47
  term: term -> term,
wenzelm@21521
    48
  fact: thm list -> thm list};
wenzelm@21476
    49
wenzelm@24031
    50
type declaration = morphism -> Context.generic -> Context.generic;
wenzelm@24031
    51
haftmann@28965
    52
fun binding (Morphism {binding, ...}) = binding;
wenzelm@21476
    53
fun typ (Morphism {typ, ...}) = typ;
wenzelm@21476
    54
fun term (Morphism {term, ...}) = term;
wenzelm@21521
    55
fun fact (Morphism {fact, ...}) = fact;
wenzelm@21521
    56
val thm = singleton o fact;
wenzelm@22235
    57
val cterm = Drule.cterm_rule o thm;
wenzelm@21476
    58
wenzelm@21476
    59
val morphism = Morphism;
wenzelm@21476
    60
wenzelm@29605
    61
fun binding_morphism binding = morphism {binding = binding, typ = I, term = I, fact = I};
wenzelm@29605
    62
fun typ_morphism typ = morphism {binding = I, typ = typ, term = I, fact = I};
wenzelm@29605
    63
fun term_morphism term = morphism {binding = I, typ = I, term = term, fact = I};
wenzelm@29605
    64
fun fact_morphism fact = morphism {binding = I, typ = I, term = I, fact = fact};
wenzelm@29605
    65
fun thm_morphism thm = morphism {binding = I, typ = I, term = I, fact = map thm};
wenzelm@21492
    66
wenzelm@29605
    67
val identity = morphism {binding = I, typ = I, term = I, fact = I};
wenzelm@21492
    68
wenzelm@22571
    69
fun compose
wenzelm@29605
    70
    (Morphism {binding = binding1, typ = typ1, term = term1, fact = fact1})
wenzelm@29605
    71
    (Morphism {binding = binding2, typ = typ2, term = term2, fact = fact2}) =
wenzelm@29605
    72
  morphism {binding = binding1 o binding2, typ = typ1 o typ2,
wenzelm@29605
    73
    term = term1 o term2, fact = fact1 o fact2};
wenzelm@21476
    74
wenzelm@22571
    75
fun phi1 $> phi2 = compose phi2 phi1;
wenzelm@21476
    76
wenzelm@22670
    77
fun transform phi f = fn psi => f (phi $> psi);
wenzelm@22670
    78
fun form f = f identity;
wenzelm@22670
    79
wenzelm@21476
    80
end;
wenzelm@21476
    81
wenzelm@21476
    82
structure BasicMorphism: BASIC_MORPHISM = Morphism;
wenzelm@21476
    83
open BasicMorphism;