packages feed

strict 0.3 → 0.3.1

raw patch · 4 files changed

+58/−4 lines, 4 filesdep ~base

Dependency ranges changed: base

Files

System/IO/Strict.hs view
@@ -42,7 +42,7 @@ --  * 'isEOFError' if the end of file has been reached.  hGetContents    :: IO.Handle -> IO.IO String-hGetContents h  = IO.hGetContents h >>= \s -> last s `seq` return s+hGetContents h  = IO.hGetContents h >>= \s -> length s `seq` return s  -- ----------------------------------------------------------------------------- -- Standard IO@@ -65,7 +65,7 @@  -- | The 'readFile' function reads a file and -- returns the contents of the file as a string.--- The file is read lazily, on demand, as with 'getContents'.+-- The file is read strictly, as with 'getContents'.  readFile        :: FilePath -> IO String readFile name   =  IO.openFile name IO.ReadMode >>= hGetContents
strict.cabal view
@@ -1,5 +1,5 @@ Name:           strict-Version:        0.3+Version:        0.3.1 Synopsis:       Strict data types and String IO. Category:       Data, System Description:@@ -13,6 +13,7 @@ Copyright:      (c) 2006-2007 by Roman Leshchinskiy Homepage:       http://www.cse.unsw.edu.au/~rl/code/strict.html Cabal-Version: >= 1.2+Build-type:     Simple  flag split-base @@ -27,5 +28,5 @@         Data.Strict.Either         Data.Strict         System.IO.Strict-  ghc-options:    -Wall -Werror -O2+  ghc-options:    -Wall   extensions:     CPP
+ tests/files.hs view
@@ -0,0 +1,18 @@+import qualified Prelude as Lazy (readFile)+import Prelude (putStrLn, putChar)+import System.IO.Strict+import Control.Monad++main = do+    let n = [0..99999]+    putStrLn "Strict IO"+    mapM_ strict n+    putChar '\n'++    putStrLn "Lazy IO"+    mapM_ lazy   n -- should fail+    putChar '\n'++ where+    strict i = do      readFile "files.hs"; putChar '!'+    lazy   i = do Lazy.readFile "files.hs"; putChar '~'
+ tests/speed.hs view
@@ -0,0 +1,35 @@++import Text.Printf+import Control.Exception+import System.CPUTime++import qualified Data.ByteString as S++import Prelude hiding (readFile)+import qualified Prelude as Lazy (readFile)+import System.IO.Strict+import Control.Monad++time :: IO t -> IO t+time a = do+    start <- getCPUTime+    v <- a+    v `seq` return ()+    end   <- getCPUTime+    let diff = (fromIntegral (end - start)) / (10^12)+    printf "Computation time: %0.3f sec\n" (diff :: Double)+    return v++main = do+    let n = [0..500]+    putStrLn "Strict IO"+    time $ mapM_ strict n+    putChar '\n'++    putStrLn "Strict ByteString IO"+    time $ mapM_ bytestring n+    putChar '\n'++ where+    strict       i = do   readFile "/usr/share/dict/words"; putChar '!'+    bytestring   i = do S.readFile "/usr/share/dict/words"; putChar '~'