src/Pure/General/stack.ML
author wenzelm
Thu Jul 19 23:18:48 2007 +0200 (2007-07-19)
changeset 23863 8f3099589cfa
parent 21272 a87b27cdd142
child 28129 8f647d24b49f
permissions -rw-r--r--
tuned signature;
     1 (*  Title:      Pure/General/stack.ML
     2     ID:         $Id$
     3     Author:     Makarius
     4 
     5 Non-empty stacks.
     6 *)
     7 
     8 signature STACK =
     9 sig
    10   type 'a T (*= 'a * 'a list*)
    11   val level: 'a T -> int
    12   val init: 'a -> 'a T
    13   val top: 'a T -> 'a
    14   val map_top: ('a -> 'a) -> 'a T -> 'a T
    15   val map_all: ('a -> 'a) -> 'a T -> 'a T
    16   val push: 'a T -> 'a T
    17   val pop: 'a T -> 'a T      (*exception Empty*)
    18 end;
    19 
    20 structure Stack: STACK =
    21 struct
    22 
    23 type 'a T = 'a * 'a list;
    24 
    25 fun level (_, xs) = length xs;
    26 
    27 fun init x = (x, []);
    28 
    29 fun top (x, _) = x;
    30 
    31 fun map_top f (x, xs) = (f x, xs);
    32 
    33 fun map_all f (x, xs) = (f x, map f xs);
    34 
    35 fun push (x, xs) = (x, x :: xs);
    36 
    37 fun pop (_, x :: xs) = (x, xs)
    38   | pop (_, []) = raise Empty;
    39 
    40 end;