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