~ubuntu-branches/ubuntu/wily/agda/wily-proposed

« back to all changes in this revision

Viewing changes to src/prototyping/nameless/Stack.hs

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-08-05 06:38:12 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140805063812-io8e77niomivhd49
Tags: 2.4.0.2-1
* [6e140ac] Imported Upstream version 2.4.0.2
* [2049fc8] Update Build-Depends to match control
* [93dc4d4] Install the new primitives
* [e48f40f] Fix typo dev→doc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
module Stack where
3
 
 
4
 
import Data.Monoid
5
 
 
6
 
infixl 5 :<, +<
7
 
 
8
 
data Stack a = Empty | Stack a :< a
9
 
  deriving (Eq, Ord)
10
 
 
11
 
instance Monoid (Stack a) where
12
 
  mempty = Empty
13
 
  mappend xs Empty     = xs
14
 
  mappend xs (ys :< y) = mappend xs ys :< y
15
 
 
16
 
(+<) :: Stack a -> Stack a -> Stack a
17
 
(+<) = mappend
18
 
 
19
 
toList :: Stack a -> [a]
20
 
toList = reverse . list where
21
 
  list (xs :< x) = x : list xs
22
 
  list Empty     = []
23
 
 
24
 
fromList :: [a] -> Stack a
25
 
fromList = foldl (:<) Empty
26
 
 
27
 
instance Show a => Show (Stack a) where
28
 
  show = show . toList