src/Pure/sorts.ML
changeset 27498 80d0de398339
parent 26994 197af793312c
child 27548 8178db4b25f3
equal deleted inserted replaced
27497:c683836fe908 27498:80d0de398339
    50   val class_error: Pretty.pp -> class_error -> string
    50   val class_error: Pretty.pp -> class_error -> string
    51   exception CLASS_ERROR of class_error
    51   exception CLASS_ERROR of class_error
    52   val mg_domain: algebra -> string -> sort -> sort list   (*exception CLASS_ERROR*)
    52   val mg_domain: algebra -> string -> sort -> sort list   (*exception CLASS_ERROR*)
    53   val meet_sort: algebra -> typ * sort -> sort Vartab.table -> sort Vartab.table
    53   val meet_sort: algebra -> typ * sort -> sort Vartab.table -> sort Vartab.table
    54   val of_sort: algebra -> typ * sort -> bool
    54   val of_sort: algebra -> typ * sort -> bool
       
    55   
       
    56 val weaken: 'b Graph.T -> ('a * class -> class -> 'a) -> 'a * class -> class -> 'a;
    55   val of_sort_derivation: Pretty.pp -> algebra ->
    57   val of_sort_derivation: Pretty.pp -> algebra ->
    56     {class_relation: 'a * class -> class -> 'a,
    58     {class_relation: 'a * class -> class -> 'a,
    57      type_constructor: string -> ('a * class) list list -> class -> 'a,
    59      type_constructor: string -> ('a * class) list list -> class -> 'a,
    58      type_variable: typ -> ('a * class) list} ->
    60      type_variable: typ -> ('a * class) list} ->
    59     typ * sort -> 'a list   (*exception CLASS_ERROR*)
    61     typ * sort -> 'a list   (*exception CLASS_ERROR*)
   366             ListPair.all ofS (Ts, Ss)
   368             ListPair.all ofS (Ts, Ss)
   367           end handle CLASS_ERROR _ => false;
   369           end handle CLASS_ERROR _ => false;
   368   in ofS end;
   370   in ofS end;
   369 
   371 
   370 
   372 
   371 (* of_sort_derivation *)
   373 (* animating derivations *)
       
   374 
       
   375 fun weaken classes class_relation (x, c1) c2 =
       
   376   (case Graph.irreducible_paths classes (c1, c2) of
       
   377     [] => raise CLASS_ERROR (NoClassrel (c1, c2))
       
   378     | cs :: _ => let
       
   379         fun weaken_path (x, c1 :: c2 :: cs) =
       
   380             weaken_path (class_relation (x, c1) c2, c2 :: cs)
       
   381           | weaken_path (x, _) = x;
       
   382       in weaken_path (x, cs) end);
   372 
   383 
   373 fun of_sort_derivation pp algebra {class_relation, type_constructor, type_variable} =
   384 fun of_sort_derivation pp algebra {class_relation, type_constructor, type_variable} =
   374   let
   385   let
   375     val {classes, arities} = rep_algebra algebra;
   386     val {classes, arities} = rep_algebra algebra;
   376     fun weaken_path (x, c1 :: c2 :: cs) =
   387     val weaken = weaken classes class_relation;
   377           weaken_path (class_relation (x, c1) c2, c2 :: cs)
       
   378       | weaken_path (x, _) = x;
       
   379     fun weaken (x, c1) c2 =
       
   380       (case Graph.irreducible_paths classes (c1, c2) of
       
   381         [] => raise CLASS_ERROR (NoClassrel (c1, c2))
       
   382       | cs :: _ => weaken_path (x, cs));
       
   383 
   388 
   384     fun weakens S1 S2 = S2 |> map (fn c2 =>
   389     fun weakens S1 S2 = S2 |> map (fn c2 =>
   385       (case S1 |> find_first (fn (_, c1) => class_le algebra (c1, c2)) of
   390       (case S1 |> find_first (fn (_, c1) => class_le algebra (c1, c2)) of
   386         SOME d1 => weaken d1 c2
   391         SOME d1 => weaken d1 c2
   387       | NONE => raise CLASS_ERROR (NoSubsort (map #2 S1, S2))));
   392       | NONE => raise CLASS_ERROR (NoSubsort (map #2 S1, S2))));