1 -- | The Misc module contains helper functions that seem out of place
7 -- | The standard factorial function. See
8 -- <http://www.willamette.edu/~fruehr/haskell/evolution.html> for
9 -- possible improvements.
19 factorial :: Int -> Int
22 | n > 20 = error "integer overflow in factorial function"
23 | otherwise = product [1..n]
26 -- | Takes a three-dimensional list, and flattens it into a
27 -- one-dimensional one.
31 -- >>> flatten [ [[1,2], [3,4]], [[5,6], [7,8]] ]
34 flatten :: [[[a]]] -> [a]
35 flatten xs = concat $ concat xs
38 -- | Takes a list, and returns True if its elements are pairwise
39 -- equal. Returns False otherwise.
40 all_equal :: (Eq a) => [a] -> Bool
42 all (== first_element) other_elements
44 first_element = head xs
45 other_elements = tail xs