{-# LANGUAGE Safe #-}
module System.IO.Strict (
hGetContents,
getContents,
readFile,
interact
) where
import Prelude ( String, (>>=), seq, return, (.), (=<<), FilePath, length)
import System.IO (IO)
import qualified System.IO as IO
hGetContents :: IO.Handle -> IO.IO String
hGetContents :: Handle -> IO String
hGetContents Handle
h = Handle -> IO String
IO.hGetContents Handle
h IO String -> (String -> IO String) -> IO String
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \String
s -> String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s Int -> IO String -> IO String
forall a b. a -> b -> b
`seq` String -> IO String
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return String
s
getContents :: IO String
getContents :: IO String
getContents = Handle -> IO String
hGetContents Handle
IO.stdin
{-# INLINE getContents #-}
interact :: (String -> String) -> IO ()
interact :: (String -> String) -> IO ()
interact String -> String
f = String -> IO ()
IO.putStr (String -> IO ()) -> (String -> String) -> String -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
f (String -> IO ()) -> IO String -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IO String
getContents
{-# INLINE interact #-}
readFile :: FilePath -> IO String
readFile :: String -> IO String
readFile String
name = String -> IOMode -> IO Handle
IO.openFile String
name IOMode
IO.ReadMode IO Handle -> (Handle -> IO String) -> IO String
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Handle -> IO String
hGetContents
{-# INLINE readFile #-}