summaryrefslogtreecommitdiffstats
path: root/stdlib/stack.ml
blob: 8b1710cdd3878b600cde2fa727941fe841b3f208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
type 'a t = { mutable c : 'a list }

exception Empty

let new () = { c = [] }

let clear s = s.c <- []

let push x s = s.c <- x :: s.c

let pop s =
  match s.c with
    hd::tl -> s.c <- tl; hd
  | []     -> raise Empty

let length s = List.length s.c

let iter f s = List.iter f s.c