package chamo

  1. Overview
  2. Docs

A stack with "forward" ability, that is "pop" does not remove top-most element which remains accessible with the "forward" operation.

type 'a t
exception Empty
val create : unit -> 'a t

create () creates an empty stack.

val push : 'a -> 'a t -> unit
val pop : 'a t -> 'a
  • raises Empty

    if the stack is empty.

val forward : 'a t -> 'a

forward stack is the contrary of pop. Since pop does not remove elements, forward can be used to return the state before the previous pop. Two calls to forward make the stack returns to the state before the two previous pop. There must not occur any push after pop, or else forward will raise Empty. Indeed, push makes the stack "forget" the states before the previous pop. Think of this stack as the "back" and "forward" buttons of a web browser: pop is the "back" button, forward is the "forward" button, and push is either the click on a link or typing a new page url.

val top : 'a t -> 'a

top s returns the topmost element in stack s, or raises Empty if the stack is empty.

val clear : 'a t -> unit

Discard all elements from a stack.

val is_empty : 'a t -> bool

Return true if the given stack is empty, false otherwise.

val can_forward : 'a t -> bool

Return true if a forward operation on the given stack will return data, false otherwise.

val length : 'a t -> int

Return the number of elements in a stack.

val forward_length : 'a t -> int

Return the number of "forward" elements in a stack.

OCaml

Innovation. Community. Security.