Saturday, October 13, 2007

Stack Examples

Here is the previous stack implementation in use.

> let xs = Cons(0, Cons(1, Cons(2, Nil)));;

val xs : int Stack

> xs;;

val it : int Stack = Cons (0,Cons (1,Cons (2,Nil)))

> let ys = Cons(3, Cons(4, Cons(5, Nil)));;

val ys : int Stack

> ys;;

val it : int Stack = Cons (3,Cons (4,Cons (5,Nil)))

> let zs = xs -||- ys;;

val zs : int Stack

> zs;;

val it : int Stack = Cons (0,Cons (1,Cons (2,Cons (3,Cons (4,Cons (5,Nil))))))

> head xs;;

val it : int = 0

> tail xs;;

val it : int Stack = Cons (1,Cons (2,Nil))

> update(xs, 1, 99);;

val it : int Stack = Cons (0,Cons (99,Cons (2,Nil)))

No comments: