Files
linguist/samples/Clean/stack.icl
Arfon Smith 9e50e188a8 Merge branch 'master' into 1233-local
Conflicts:
	lib/linguist/language.rb
	lib/linguist/languages.yml
	lib/linguist/samples.json
2014-11-01 10:04:22 -05:00

34 lines
580 B
Plaintext

implementation module stack
import StdEnv
:: Stack a :== [a]
newStack :: (Stack a)
newStack = []
push :: a (Stack a) -> Stack a
push x s = [x:s]
pushes :: [a] (Stack a) -> Stack a
pushes x s = x ++ s
pop :: (Stack a) -> Stack a
pop [] = abort "Cannot use pop on an empty stack"
pop [e:s] = s
popn :: Int (Stack a) -> Stack a
popn n s = drop n s
top :: (Stack a) -> a
top [] = abort "Cannot use top on an empty stack"
top [e:s] = e
topn :: Int (Stack a) -> [a]
topn n s = take n s
elements :: (Stack a) -> [a]
elements s = s
count :: (Stack a) -> Int
count s = length s