Hello I have just made a stack module which works, but my teacher tells me it should be possible using an array?
If possible could someone give me a small tips on how to convert it?
module Stack : STACK =
struct
type 'a stack = 'a list
exception EmptyStack
let empty : 'a stack = []
let isEmpty (l : 'a list) : bool = l = []
let push ((x : 'a), (l : 'a stack)) : 'a stack = x :: l
let pop (l : 'a stack) : 'a stack =
match l with
[] -> raise EmptyStack
| x :: xs -> xs
let top (l : 'a stack) : 'a =
match l with
[] -> raise EmptyStack
| x :: xs -> x