working on w3
[fp1415.git] / week3 / camil / StdStack.icl
1 implementation module StdStack
2
3 import StdEnv
4
5 :: Stack a :== [a]
6
7 newStack :: (Stack a)
8 newStack = []
9
10 push :: a (Stack a) -> (Stack a)
11 push a s = s ++ [a]
12
13 pop
14
15 Start = ( "s0 = newStack = ", s0,'\n'
16 , "s1 = push 1 s0 = ", s1,'\n'
17 , "s2 = pushes [2..5] s1 = ",s2,'\n'
18 , "s3 = pop s2 = ", s3,'\n'
19 , "s4 = popn 3 s3 = ", s4,'\n'
20 , "s5 = top s4 = ", s5,'\n'
21 , "s6 = topn 3 s2 = ", s6,'\n'
22 , "s7 = elements s2 = ", s7,'\n'
23 )
24 where
25 s0 = newStack
26 s1 = push 1 s0
27 s2 = pushes [2..5] s1
28 s3 = pop s2
29 s4 = popn 3 s3
30 s5 = top s4
31 s6 = topn 3 s2
32 s7 = elements s2