File: Test109.ML

package info (click to toggle)
polyml 5.7.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 40,616 kB
  • sloc: cpp: 44,142; ansic: 26,963; sh: 22,002; asm: 13,486; makefile: 602; exp: 525; python: 253; awk: 91
file content (75 lines) | stat: -rw-r--r-- 2,065 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
(* This produced an InternalError exception.  That check has been removed but the
   test has been included because it may be useful to revisit this. *)

type polarity = int


datatype rep =
    Atom of int * int |
    Struct of rep list |
    Vect of int * rep |
    Func of rep * rep
;
exception REP of string * rep list;
exception LIMIT of string * string;

PolyML.Compiler.maxInlineSize := 1;
fun card_of_rep (_: rep): int = (PolyML.print "card_of_rep"; raise Match);
fun is_lone_rep (_: rep): bool = (PolyML.print "is_lone_rep"; raise Match);
fun kk_case_switch _ = (PolyML.print "kk_case_switch"; raise Match);
fun all_singletons_for_rep _ = (PolyML.print "all_singletons_for_rep"; raise Match);

PolyML.Compiler.maxInlineSize := 60;

structure S
 =
struct

exception E

fun vect_from_rel_expr a b c d e = (
    PolyML.print a;
    PolyML.print b;
    PolyML.print c;
    PolyML.print d;
    PolyML.print e;
    PolyML.print a;
    PolyML.print b;
    PolyML.print c;
    raise E
);

fun lone_rep_fallback kk new_R old_R r =
  if old_R = new_R then
    r
  else
    let val card = card_of_rep old_R in
      if is_lone_rep old_R andalso is_lone_rep new_R
         andalso card = card_of_rep new_R then
        if card >= 4096 then
          raise LIMIT ("lone_rep_fallback",
                       "too high cardinality (" ^ Int.toString card ^ ")")
        else
          kk_case_switch kk old_R new_R r (all_singletons_for_rep old_R)
                         (all_singletons_for_rep new_R)
      else
        raise REP ("lone_rep_fallback", [old_R, new_R])
    end

and atom_from_rel_expr kk (x as (k, j0)) old_R r =
  case old_R of
    Func (R1, R2) =>
    let
      val dom_card = card_of_rep R1
      val R2' = case R2 of Atom _ => R2 | _ => Atom (card_of_rep R2, 0)
    in
      atom_from_rel_expr kk x (Vect (dom_card, R2'))
                         (vect_from_rel_expr kk dom_card R2' old_R r)
    end
  | _ => lone_rep_fallback kk (Atom x) old_R r


fun yy a kk x c d y =
    (if a then atom_from_rel_expr kk (c, d) else fn _ => raise Match) y
end
;