src/Pure/typedecl.ML
changeset 25465 40d8409146f0
parent 25458 ba8f5e4fa336
equal deleted inserted replaced
25464:0ca80ce89001 25465:40d8409146f0
     1 (*  Title:      Pure/typedecl.ML
     1 (*  Title:      Pure/typedecl.ML
     2     ID:         $Id$
     2     ID:         $Id$
     3     Author:     Florian Haftmann, TU Muenchen
     3     Author:     Florian Haftmann, TU Muenchen
     4 
     4 
     5 Primitive type declarations.
     5 Type declarations with interpretation.
     6 *)
     6 *)
     7 
     7 
     8 signature TYPEDECL =
     8 signature TYPEDECL =
     9 sig
     9 sig
    10   val add: bstring * string list * mixfix -> theory -> typ * theory
    10   val add: bstring * string list * mixfix -> theory -> typ * theory
    17 structure TypedeclInterpretation = InterpretationFun(type T = string val eq = op =);
    17 structure TypedeclInterpretation = InterpretationFun(type T = string val eq = op =);
    18 val interpretation = TypedeclInterpretation.interpretation;
    18 val interpretation = TypedeclInterpretation.interpretation;
    19 
    19 
    20 val _ = Context.add_setup TypedeclInterpretation.init;
    20 val _ = Context.add_setup TypedeclInterpretation.init;
    21 
    21 
    22 fun add (a, vs : string list, mx) thy =
    22 fun add (a, vs, mx) thy =
    23   let
    23   let
    24     val no_typargs = if not (has_duplicates (op =) vs) then length vs
    24     val _ = has_duplicates (op =) vs andalso
    25       else error ("Duplicate parameters in type declaration: " ^ quote a);
    25       error ("Duplicate parameters in type declaration: " ^ quote a);
    26     val a' = Sign.full_name thy a;
    26     val a' = Sign.full_name thy a;
    27     val T = Type (a', map (fn v => TFree (v, [])) vs);
    27     val T = Type (a', map (fn v => TFree (v, [])) vs);
    28   in
    28   in
    29     thy
    29     thy
    30     |> Sign.add_types [(a, no_typargs, mx)]
    30     |> Sign.add_types [(a, length vs, mx)]
    31     |> TypedeclInterpretation.data a'
    31     |> TypedeclInterpretation.data a'
    32     |> pair T
    32     |> pair T
    33   end;
    33   end;
    34 
    34 
    35 end;
    35 end;