never executed always true always false
1 module Data.ReversedList where
2
3 {-|
4 ReversedList can be used to avoid accidentally forgetting to reverse a list
5 (this most commonly occurs when implementing recursive algorithms that build up a
6 list that needs to be reversed in the termination case).
7 -}
8
9 newtype Reversed a = Reversed [a]
10
11
12 empty :: Reversed a
13 empty =
14 Reversed []
15
16
17 push :: a -> Reversed a -> Reversed a
18 push a (Reversed list) =
19 Reversed (a : list)
20
21
22 isEmpty :: Reversed a -> Bool
23 isEmpty (Reversed []) = True
24 isEmpty _ = False
25
26
27 toList :: Reversed a -> [a]
28 toList (Reversed list) =
29 reverse list