Bounded Stomp Stack of E (BSS)


datatype BSS = 
   New of int  
   | push of BSS * int 
   ;

fun empty (New(n)) = true 
  | empty (push(B,e)) = false 
  ;

fun max (New(n)) = n
  | max (push(B,e)) = max(B) 
  ;

fun size (New(n)) = 0
  | size (push(B,e)) = if size(B)=max(B)
                        then size(B)
                        else size(B)+1 
  ;

fun full (New(m)) = false
  | full (push(B,e)) = if size(B)>=max(B)-1
                        then true
                        else false 
  ;

exception topEmptyStack;

fun top (New(n)) = raise topEmptyStack 
  | top (push(B,e)) = e
  ;

fun pop (New(n)) = New(n)
  | pop (push(B,e)) = if full(B)
                       then push(stomp(B),e)
                       else B 
  ;

fun stomp(New(n)) = New(n)
  | stomp(push(B,e)) = if empty(B) 
                         then B
                         else push(stomp(B),e)
  ;