// Exercise 2.19
type 'a Stack = EmptyStack | ExtendedStack of 'a * 'a Stack
let empty_stack () =
EmptyStack
let push elt stk =
ExtendedStack (elt, stk)
let pop stk =
match stk with
EmptyStack -> failwith "Stack empty"
| ExtendedStack (_, s) -> s
let top stk =
match stk with
EmptyStack -> failwith "Stack empty"
| ExtendedStack (e, _) -> e
let is_stack_empty stk =
stk = EmptyStack
Tuesday, March 6, 2007
EOPL - 2.3.3 - Exercise 2.19
Another simple exercise.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment