src/Pure/General/stack.ML
author blanchet
Fri, 20 Dec 2013 20:36:38 +0100
changeset 54838 16511f84913c
parent 49063 f93443defa6c
child 58797 6d71f19a9fd6
permissions -rw-r--r--
reconstruct SPASS-Pirate steps of the form 'x ~= C x' (or more complicated)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17368
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/General/stack.ML
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
     3
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
     4
Non-empty stacks.
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
     5
*)
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
     6
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
     7
signature STACK =
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
     8
sig
28129
8f647d24b49f tuned signature;
wenzelm
parents: 21272
diff changeset
     9
  type 'a T = 'a * 'a list
17368
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    10
  val level: 'a T -> int
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    11
  val init: 'a -> 'a T
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    12
  val top: 'a T -> 'a
21272
a87b27cdd142 separate map_top/all;
wenzelm
parents: 17756
diff changeset
    13
  val map_top: ('a -> 'a) -> 'a T -> 'a T
a87b27cdd142 separate map_top/all;
wenzelm
parents: 17756
diff changeset
    14
  val map_all: ('a -> 'a) -> 'a T -> 'a T
17368
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    15
  val push: 'a T -> 'a T
47060
e2741ec9ae36 prefer explicitly qualified exception List.Empty;
wenzelm
parents: 29606
diff changeset
    16
  val pop: 'a T -> 'a T      (*exception List.Empty*)
17368
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    17
end;
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    18
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    19
structure Stack: STACK =
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    20
struct
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    21
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    22
type 'a T = 'a * 'a list;
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    23
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    24
fun level (_, xs) = length xs;
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    25
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    26
fun init x = (x, []);
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    27
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    28
fun top (x, _) = x;
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    29
21272
a87b27cdd142 separate map_top/all;
wenzelm
parents: 17756
diff changeset
    30
fun map_top f (x, xs) = (f x, xs);
a87b27cdd142 separate map_top/all;
wenzelm
parents: 17756
diff changeset
    31
a87b27cdd142 separate map_top/all;
wenzelm
parents: 17756
diff changeset
    32
fun map_all f (x, xs) = (f x, map f xs);
17368
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    33
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    34
fun push (x, xs) = (x, x :: xs);
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    35
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    36
fun pop (_, x :: xs) = (x, xs)
47060
e2741ec9ae36 prefer explicitly qualified exception List.Empty;
wenzelm
parents: 29606
diff changeset
    37
  | pop (_, []) = raise List.Empty;
17368
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    38
e02adca07c31 Non-empty stacks.
wenzelm
parents:
diff changeset
    39
end;