Stacks
newtype Stack a = Stk [a] deriving Show push x (Stk xs) = Stk (x:xs) pop (Stk []) = error "pop from an empty stack" pop (Stk (_:xs)) = Stk xs top (Stk []) = error "top from an empty stack" top (Stk (x:_)) = x emptyStack = Stk [] stackEmpty (Stk []) = True stackEmpty (Stk _ ) = False
ตัวอย่างการเรียกใช้งาน
$ hugs Stacks.hs Main> push 5 (push 3 (push 1 emptyStack)) Stk [5,3,1] Main> top (push 5 (push 3 (push 1 emptyStack))) 5 Main> pop (push 5 (push 3 (push 1 emptyStack))) Stk [3,1]



Recent comments
1 week 23 hours ago
3 weeks 4 days ago
5 weeks 1 hour ago
7 weeks 1 day ago
20 weeks 1 day ago
22 weeks 4 days ago
26 weeks 1 day ago
26 weeks 1 day ago
27 weeks 4 days ago
44 weeks 2 days ago