[Haskell-beginners] please critique my first stab at systems programming
Felipe Almeida Lessa
felipe.lessa at gmail.com
Thu Apr 14 14:30:59 CEST 2011
On Thu, Apr 14, 2011 at 8:50 AM, Daniel Fischer
<daniel.is.fischer at googlemail.com> wrote:
> $ cabal install stringsearch
> -- faster searches for a pattern than provided by bytestring
> import qualified Data.ByteString.Char8 as BC
> import qualified Data.ByteString.Lazy as L
> import qualified Data.ByteString.Lazy.Search as L
> blockSize = 512
> main = do
> stuff <- L.readFile "blocks"
> case L.indices (BC.pack "PART") stuff of
>  -> putStrLn "Not Found."
> (i:_) -> putStrLn $ "Found at " ++ show (i `quot` blockSize) ++ "."
> putStrLn "Done."
This solves a different problem. The original looked for PART only on
the beginning of each block, while your solution will find everything
that has PART in it. Because this is I/O bound, probably the real
time taken won't be very different, but the program will surely use
more CPU time and report more false positives.
More information about the Beginners