src/Pure/morphism.ML
author wenzelm
Sat, 28 Jul 2007 22:01:06 +0200
changeset 24031 e94e541346d7
parent 22670 c803b2696ada
child 28074 90adbbf03187
permissions -rw-r--r--
type Morphism.declaration;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/morphism.ML
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     4
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     5
Abstract morphisms on formal entities.
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     6
*)
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     7
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     8
infix 1 $>
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
     9
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    10
signature BASIC_MORPHISM =
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    11
sig
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    12
  type morphism
24031
e94e541346d7 type Morphism.declaration;
wenzelm
parents: 22670
diff changeset
    13
  type declaration = morphism -> Context.generic -> Context.generic
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    14
  val $> : morphism * morphism -> morphism
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    15
end
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    16
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    17
signature MORPHISM =
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    18
sig
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    19
  include BASIC_MORPHISM
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    20
  val var: morphism -> string * mixfix -> string * mixfix
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    21
  val name: morphism -> string -> string
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    22
  val typ: morphism -> typ -> typ
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    23
  val term: morphism -> term -> term
21521
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    24
  val fact: morphism -> thm list -> thm list
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    25
  val thm: morphism -> thm -> thm
22235
6eac7f7c3294 added cterm interface;
wenzelm
parents: 21521
diff changeset
    26
  val cterm: morphism -> cterm -> cterm
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    27
  val morphism:
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    28
   {name: string -> string,
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    29
    var: string * mixfix -> string * mixfix,
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    30
    typ: typ -> typ,
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    31
    term: term -> term,
21521
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    32
    fact: thm list -> thm list} -> morphism
21492
c73faa8e98aa added name/var/typ/term/thm_morphism;
wenzelm
parents: 21476
diff changeset
    33
  val name_morphism: (string -> string) -> morphism
c73faa8e98aa added name/var/typ/term/thm_morphism;
wenzelm
parents: 21476
diff changeset
    34
  val var_morphism: (string * mixfix -> string * mixfix) -> morphism
c73faa8e98aa added name/var/typ/term/thm_morphism;
wenzelm
parents: 21476
diff changeset
    35
  val typ_morphism: (typ -> typ) -> morphism
c73faa8e98aa added name/var/typ/term/thm_morphism;
wenzelm
parents: 21476
diff changeset
    36
  val term_morphism: (term -> term) -> morphism
21521
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    37
  val fact_morphism: (thm list -> thm list) -> morphism
21492
c73faa8e98aa added name/var/typ/term/thm_morphism;
wenzelm
parents: 21476
diff changeset
    38
  val thm_morphism: (thm -> thm) -> morphism
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    39
  val identity: morphism
22571
3f00e937d1c9 renamed comp to compose (avoid clash with Alice keywords);
wenzelm
parents: 22235
diff changeset
    40
  val compose: morphism -> morphism -> morphism
22670
c803b2696ada added Morphism.transform/form (generic non-sense);
wenzelm
parents: 22571
diff changeset
    41
  val transform: morphism -> (morphism -> 'a) -> morphism -> 'a
c803b2696ada added Morphism.transform/form (generic non-sense);
wenzelm
parents: 22571
diff changeset
    42
  val form: (morphism -> 'a) -> 'a
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    43
end;
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    44
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    45
structure Morphism: MORPHISM =
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    46
struct
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    47
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    48
datatype morphism = Morphism of
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    49
 {name: string -> string,
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    50
  var: string * mixfix -> string * mixfix,
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    51
  typ: typ -> typ,
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    52
  term: term -> term,
21521
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    53
  fact: thm list -> thm list};
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    54
24031
e94e541346d7 type Morphism.declaration;
wenzelm
parents: 22670
diff changeset
    55
type declaration = morphism -> Context.generic -> Context.generic;
e94e541346d7 type Morphism.declaration;
wenzelm
parents: 22670
diff changeset
    56
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    57
fun name (Morphism {name, ...}) = name;
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    58
fun var (Morphism {var, ...}) = var;
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    59
fun typ (Morphism {typ, ...}) = typ;
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    60
fun term (Morphism {term, ...}) = term;
21521
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    61
fun fact (Morphism {fact, ...}) = fact;
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    62
val thm = singleton o fact;
22235
6eac7f7c3294 added cterm interface;
wenzelm
parents: 21521
diff changeset
    63
val cterm = Drule.cterm_rule o thm;
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    64
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    65
val morphism = Morphism;
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    66
21521
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    67
fun name_morphism name = morphism {name = name, var = I, typ = I, term = I, fact = I};
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    68
fun var_morphism var = morphism {name = I, var = var, typ = I, term = I, fact = I};
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    69
fun typ_morphism typ = morphism {name = I, var = I, typ = typ, term = I, fact = I};
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    70
fun term_morphism term = morphism {name = I, var = I, typ = I, term = term, fact = I};
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    71
fun fact_morphism fact = morphism {name = I, var = I, typ = I, term = I, fact = fact};
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    72
fun thm_morphism thm = morphism {name = I, var = I, typ = I, term = I, fact = map thm};
21492
c73faa8e98aa added name/var/typ/term/thm_morphism;
wenzelm
parents: 21476
diff changeset
    73
21521
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    74
val identity = morphism {name = I, var = I, typ = I, term = I, fact = I};
21492
c73faa8e98aa added name/var/typ/term/thm_morphism;
wenzelm
parents: 21476
diff changeset
    75
22571
3f00e937d1c9 renamed comp to compose (avoid clash with Alice keywords);
wenzelm
parents: 22235
diff changeset
    76
fun compose
21521
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    77
    (Morphism {name = name1, var = var1, typ = typ1, term = term1, fact = fact1})
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    78
    (Morphism {name = name2, var = var2, typ = typ2, term = term2, fact = fact2}) =
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    79
  morphism {name = name1 o name2, var = var1 o var2,
21521
095f4963beed simultaneous fact morphism;
wenzelm
parents: 21492
diff changeset
    80
    typ = typ1 o typ2, term = term1 o term2, fact = fact1 o fact2};
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    81
22571
3f00e937d1c9 renamed comp to compose (avoid clash with Alice keywords);
wenzelm
parents: 22235
diff changeset
    82
fun phi1 $> phi2 = compose phi2 phi1;
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    83
22670
c803b2696ada added Morphism.transform/form (generic non-sense);
wenzelm
parents: 22571
diff changeset
    84
fun transform phi f = fn psi => f (phi $> psi);
c803b2696ada added Morphism.transform/form (generic non-sense);
wenzelm
parents: 22571
diff changeset
    85
fun form f = f identity;
c803b2696ada added Morphism.transform/form (generic non-sense);
wenzelm
parents: 22571
diff changeset
    86
21476
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    87
end;
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    88
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    89
structure BasicMorphism: BASIC_MORPHISM = Morphism;
4677b7b84247 Abstract morphisms on formal entities.
wenzelm
parents:
diff changeset
    90
open BasicMorphism;