1 -- | The Misc module contains helper functions that seem out of place
6 import Data.List (intersect)
9 -- | The standard factorial function. See
10 -- <http://www.willamette.edu/~fruehr/haskell/evolution.html> for
11 -- possible improvements.
21 factorial :: Int -> Int
24 | n > 20 = error "integer overflow in factorial function"
25 | otherwise = product [1..n]
28 -- | Takes a three-dimensional list, and flattens it into a
29 -- one-dimensional one.
33 -- >>> flatten [ [[1,2], [3,4]], [[5,6], [7,8]] ]
36 flatten :: [[[a]]] -> [a]
37 flatten xs = concat $ concat xs
40 -- | Switch the x and z dimensions of a three-dimensional list.
41 transpose_xz :: [[[a]]] -> [[[a]]]
43 transpose_xz [[]] = [[]]
44 transpose_xz [[[]]] = [[[]]]
46 [[[ m !! x !! y !! z | x <- [0..xsize]]
50 zsize = (length m) - 1
51 ysize = length (head m) - 1
52 xsize = length (head $ head m) - 1
54 -- | Takes a list, and returns True if its elements are pairwise
55 -- equal. Returns False otherwise.
56 all_equal :: (Eq a) => [a] -> Bool
58 all (== first_element) other_elements
60 first_element = head xs
61 other_elements = tail xs
64 -- | Returns 'True' if the lists xs and ys are disjoint, 'False'
69 -- >>> disjoint [1,2,3] [4,5,6]
72 -- >>> disjoint [1,2,3] [3,4,5]
75 disjoint :: (Eq a) => [a] -> [a] -> Bool