, debugFn
, debugXy
, sepSplit
- , varianceCoeff
+ , stdDev
, commaJoin
, readEitherString
, loadJSArray
commaJoin :: [String] -> String
commaJoin = intercalate ","
--- | Split a string on a separator and return an array.
-sepSplit :: Char -> String -> [String]
+-- | Split a list on a separator and return an array.
+sepSplit :: Eq a => a -> [a] -> [[a]]
sepSplit sep s
- | x == "" && xs == [] = []
- | xs == [] = [x]
- | ys == [] = [x,""]
- | otherwise = x:sepSplit sep ys
+ | null s = []
+ | null xs = [x]
+ | null ys = [x,[]]
+ | otherwise = x:sepSplit sep ys
where (x, xs) = break (== sep) s
ys = drop 1 xs
-- Simple and slow statistical functions, please replace with better
-- versions
--- | Our modified standard deviation function (not, it's not the variance)
-varianceCoeff :: [Double] -> Double
-varianceCoeff lst =
+-- | Standard deviation function
+stdDev :: [Double] -> Double
+stdDev lst =
-- first, calculate the list length and sum lst in a single step,
-- for performance reasons
let (ll', sx) = foldl' (\(rl, rs) e ->
ll = fromIntegral ll'::Double
mv = sx / ll
av = foldl' (\accu em -> let d = em - mv in accu + d * d) 0.0 lst
- bv = sqrt (av / ll) -- stddev
- cv = bv / ll -- standard deviation divided by list length
- in cv
+ in sqrt (av / ll) -- stddev
-- * JSON-related functions