playing with >=>
Apparently in haskell if you teach a man to fish, he'll write more pointfree code.
This commit is contained in:
parent
3d2a9f8405
commit
c643136e32
4 changed files with 7 additions and 6 deletions
|
@ -8,15 +8,16 @@
|
|||
module Utility.Misc where
|
||||
|
||||
import System.IO
|
||||
import Control.Monad
|
||||
|
||||
{- A version of hgetContents that is not lazy. Ensures file is
|
||||
- all read before it gets closed. -}
|
||||
hGetContentsStrict :: Handle -> IO String
|
||||
hGetContentsStrict h = hGetContents h >>= \s -> length s `seq` return s
|
||||
hGetContentsStrict = hGetContents >=> \s -> length s `seq` return s
|
||||
|
||||
{- A version of readFile that is not lazy. -}
|
||||
readFileStrict :: FilePath -> IO String
|
||||
readFileStrict f = readFile f >>= \s -> length s `seq` return s
|
||||
readFileStrict = readFile >=> \s -> length s `seq` return s
|
||||
|
||||
{- Attempts to read a value from a String. -}
|
||||
readMaybe :: (Read a) => String -> Maybe a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue