On 03/19/2013 10:53 PM, Nicolas Trangez wrote:
On Tue, 2013-03-19 at 20:32 +0000, Don Stewart wrote:
So about 8x faster. Waiting for some non-lazy bytestring benchmarks... :)
You could try something like this using Conduit:
{-# LANGUAGE BangPatterns #-}
module Main (main) where
import Data.Conduit
import qualified Data.Conduit.List as L
import qualified Data.Conduit.Binary as B
import qualified Data.ByteString.Char8 as BS8
main :: IO ()
main = print =<< runResourceT (
B.sourceFile filename $$ L.fold (\(!a) (!b) -> a + BS8.count ' ' b)
(0 :: Int))
where
filename = ...
Please stops counting spaces! :) It was a MODEL that demonstrates
constant allocation of state when I used State monad. That's the
*problem*. I mention in my first email that I do know how to count
spaces using one-line L.foldl with no allocations at all :).
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe