strict 0.2 → 0.3
raw patch · 2 files changed
+82/−8 lines, 2 files
Files
- System/IO/Strict.hs +72/−0
- strict.cabal +10/−8
+ System/IO/Strict.hs view
@@ -0,0 +1,72 @@+-----------------------------------------------------------------------------+-- |+-- Module : System.IO.Strict+-- Copyright : (c) Don Stewart 2007+-- License : BSD-style (see the file libraries/base/LICENSE)+-- +-- Maintainer : dons@galois.com+-- Stability : stable+-- Portability : portable+--+-- The standard IO input functions using strict IO.+--+-----------------------------------------------------------------------------++module System.IO.Strict (++ -- * Strict Handle IO+ hGetContents, -- :: Handle -> IO [Char]++ -- * Strict String IO wrappers+ getContents, -- :: IO String+ readFile, -- :: FilePath -> IO String+ interact -- :: (String -> String) -> IO ()++ ) where++import Prelude ( String, (>>=), last, seq, return, (.), (=<<), FilePath)+import System.IO (IO)+import qualified System.IO as IO++-- -----------------------------------------------------------------------------+-- Strict hGetContents++-- | Computation 'hGetContents' @hdl@ returns the list of characters+-- corresponding to the unread portion of the channel or file managed+-- by @hdl@, which is immediate closed.+--+-- Items are read strictly from the input Handle.+--+-- This operation may fail with:+--+-- * '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++-- -----------------------------------------------------------------------------+-- Standard IO++-- | The 'getContents' operation returns all user input as a single string,+-- which is read stirctly (same as 'hGetContents' 'stdin').++getContents :: IO String+getContents = hGetContents IO.stdin+{-# INLINE getContents #-}++-- | The 'interact' function takes a function of type @String->String@+-- as its argument. The entire input from the standard input device is+-- passed to this function as its argument, and the resulting string is+-- output on the standard output device.++interact :: (String -> String) -> IO ()+interact f = IO.putStr . f =<< getContents+{-# INLINE interact #-}++-- | 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'.++readFile :: FilePath -> IO String+readFile name = IO.openFile name IO.ReadMode >>= hGetContents+{-# INLINE readFile #-}
strict.cabal view
@@ -1,14 +1,15 @@ Name: strict-Version: 0.2-Synopsis: Strict data types-Category: Data+Version: 0.3+Synopsis: Strict data types and String IO.+Category: Data, System Description: This package provides strict versions of some standard Haskell data- types (pairs, Maybe and Either at the moment).+ types (pairs, Maybe and Either). It also contains strict IO+ operations. License: BSD3 License-File: LICENSE Author: Roman Leshchinskiy <rl@cse.unsw.edu.au>-Maintainer: Roman Leshchinskiy <rl@cse.unsw.edu.au>+Maintainer: Don Stewart <dons@galois.com> Copyright: (c) 2006-2007 by Roman Leshchinskiy Homepage: http://www.cse.unsw.edu.au/~rl/code/strict.html Cabal-Version: >= 1.2@@ -21,9 +22,10 @@ else build-depends: base < 3 exposed-modules:- Data.Strict.Tuple,- Data.Strict.Maybe,- Data.Strict.Either,+ Data.Strict.Tuple+ Data.Strict.Maybe+ Data.Strict.Either Data.Strict+ System.IO.Strict ghc-options: -Wall -Werror -O2 extensions: CPP