News for hackers. Stuff that matters.
Re:Four MLs (and a Python) by drostie on Thursday April 30, 2015 @01:35PM (#9466453)
This is the start of a solution in Haskell:

    import System.Environment
    import qualified Data.Vector.Unboxed as V
    import Data.Vector.Unboxed (Vector)

    display :: Vector Double -> String
    display ds | V.null ds = ""
            | otherwise = tail . concatMap format . V.toList $ ds
                    where format d = ',' : show d

    csv_sums :: String -> Vector Double
    csv_sums input = go (V.length $ h) 1 h t where
        h : t = map (V.fromList . read . bracket) $ lines input
        bracket s = '[' : s ++ "]"
        go s n summary [] = summary
        go s n summary (x:xs)
            | V.length x == s  = go s (n + 1) (V.zipWith (+) summary x) xs
            | otherwise        = if blankLastLine then summary
                                                else error "Inconsistent lengths."
                where blankLastLine = case xs of [] -> V.length x == 0
                                                _  -> False

    main = do
        paths <- getArgs
        if length paths /= 1
            then error "Exactly one filename must be given."
            else readFile (head paths) >>= putStrLn . display . csv_sums
It takes about 22x longer than Python on my platform though, which I'm not sure how to solve. (The vector keeps it nice and un-thunked so it doesn't seem like it's laziness that's killing it, maybe it's the use of strings over Data.ByteString.Lazy or so?)
Re:Four MLs (and a Python) by Codas on Friday May 01, 2015 @06:40AM (#9470507)
The main problem is probably creating and traversing the strings, although I have not benchmarked it. This version https://gist.github.com/Codas/894694eea247aaacf35f runs about 4 times faster than the python version on my machine.

It does use some libraries that are not in the haskell platform though.

Re:Four MLs (and a Python) by drostie on Friday May 01, 2015 @10:55AM (#9471763)
Very cool!