module StackADT (Stack, createStack, push, empty, top, pop) where import Prelude data Stack a = Stack [a] deriving (Eq, Show) createStack :: Stack a createStack = Stack [] push :: a -> Stack a -> Stack a push x (Stack s) = Stack (x:s) empty :: Stack a -> Bool empty (Stack s) = null s top :: Stack a -> a top (Stack s) | null s = error "stack is empty" | otherwise = head s poptop :: Stack a -> (a, Stack a) poptop s = (top s, pop s) pop :: Stack a -> Stack a pop (Stack s) | null s = error "stack is empty" | otherwise = Stack (tail s) --- -- Using stack s = createStack s2 = push 1 s s3 = ((push 1) . (push 2)) s t = top s3