/usr/share/doc/hugs/examples/Stack.hs is in hugs 98.200609.21-5.3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | -- Stacks: using restricted type synonyms
module Stack where
type Stack a = [a] in emptyStack, push, pop, topOf, isEmpty
emptyStack :: Stack a
emptyStack = []
push :: a -> Stack a -> Stack a
push = (:)
pop :: Stack a -> Stack a
pop [] = error "pop: empty stack"
pop (_:xs) = xs
topOf :: Stack a -> a
topOf [] = error "topOf: empty stack"
topOf (x:_) = x
isEmpty :: Stack a -> Bool
isEmpty = null
instance Eq a => Eq (Stack a) where
s1 == s2 | isEmpty s1 = isEmpty s2
| isEmpty s2 = isEmpty s1
| otherwise = topOf s1 == topOf s2 && pop s1 == pop s2
-- A slightly different presentation:
type Stack' a = [a] in
emptyStack' :: Stack' a,
push' :: a -> Stack' a -> Stack' a,
pop' :: Stack' a -> Stack' a,
topOf' :: Stack' a -> a,
isEmpty' :: Stack' a -> Bool
emptyStack' = []
push' = (:)
pop' [] = error "pop': empty stack"
pop' (_:xs) = xs
topOf' [] = error "topOf': empty stack"
topOf' (x:_) = x
isEmpty' = null
instance Eq a => Eq (Stack' a) where
s1 == s2 | isEmpty' s1 = isEmpty' s2
| isEmpty' s2 = isEmpty' s1
| otherwise = topOf' s1 == topOf' s2 && pop' s1 == pop' s2
|