1 {-| Utility functions -}
9 -- | To be used only for debugging, breaks referential integrity.
10 debug :: Show a => a -> a
11 debug x = trace (show x) x
13 -- | Comma-join a string list.
14 commaJoin :: [String] -> String
15 commaJoin = intercalate ","
17 -- | Split a string on a separator and return an array.
18 sepSplit :: Char -> String -> [String]
20 | x == "" && xs == [] = []
23 | otherwise = x:(sepSplit sep ys)
24 where (x, xs) = break (== sep) s
27 -- | Partial application of sepSplit to @'.'@
28 commaSplit :: String -> [String]
29 commaSplit = sepSplit ','
31 -- | Swap a list of @(a, b)@ into @(b, a)@
32 swapPairs :: [(a, b)] -> [(b, a)]
33 swapPairs = map (\ (a, b) -> (b, a))
35 -- Simple and slow statistical functions, please replace with better versions
37 -- | Mean value of a list.
38 meanValue :: Floating a => [a] -> a
39 meanValue lst = (sum lst) / (fromIntegral $ length lst)
41 -- | Standard deviation.
42 stdDev :: Floating a => [a] -> a
44 let mv = meanValue lst
45 square = (^ (2::Int)) -- silences "defaulting the constraint..."
46 av = sum $ map square $ map (\e -> e - mv) lst
47 bv = sqrt (av / (fromIntegral $ length lst))
51 -- | Coefficient of variation.
52 varianceCoeff :: Floating a => [a] -> a
53 varianceCoeff lst = (stdDev lst) / (fromIntegral $ length lst)