Add hPutStr and hPutStrLn (#52)

This commit is contained in:
Moritz Kiefer
2017-05-03 10:01:19 +01:00
committed by Stephen Diehl
parent 41710698ee
commit 307ecd7d6a
2 changed files with 19 additions and 10 deletions
+2
View File
@@ -525,6 +525,8 @@
* head * head
* headDef * headDef
* headMay * headMay
* hPutStr
* hPutStrLn
* identity * identity
* ifM * ifM
* imagPart * imagPart
+17 -10
View File
@@ -14,6 +14,7 @@ module Show (
) where ) where
import qualified Base import qualified Base
import qualified System.IO as Base
import Data.Function ((.)) import Data.Function ((.))
import Control.Monad.IO.Class (MonadIO, liftIO) import Control.Monad.IO.Class (MonadIO, liftIO)
@@ -26,30 +27,36 @@ import qualified Data.Text.IO as T
import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.IO as TL import qualified Data.Text.Lazy.IO as TL
import System.IO (Handle, stdout)
class Print a where class Print a where
hPutStr :: MonadIO m => Handle -> a -> m ()
putStr :: MonadIO m => a -> m () putStr :: MonadIO m => a -> m ()
putStr = hPutStr stdout
hPutStrLn :: MonadIO m => Handle -> a -> m ()
putStrLn :: MonadIO m => a -> m () putStrLn :: MonadIO m => a -> m ()
putStrLn = hPutStrLn stdout
instance Print T.Text where instance Print T.Text where
putStr = liftIO . T.putStr hPutStr = \h -> liftIO . T.hPutStr h
putStrLn = liftIO . T.putStrLn hPutStrLn = \h -> liftIO . T.hPutStrLn h
instance Print TL.Text where instance Print TL.Text where
putStr = liftIO . TL.putStr hPutStr = \h -> liftIO . TL.hPutStr h
putStrLn = liftIO . TL.putStrLn hPutStrLn = \h -> liftIO . TL.hPutStrLn h
instance Print BS.ByteString where instance Print BS.ByteString where
putStr = liftIO . BS.putStr hPutStr = \h -> liftIO . BS.hPutStr h
putStrLn = liftIO . BS.putStrLn hPutStrLn = \h -> liftIO . BS.hPutStrLn h
instance Print BL.ByteString where instance Print BL.ByteString where
putStr = liftIO . BL.putStr hPutStr = \h -> liftIO . BL.hPutStr h
putStrLn = liftIO . BL.putStrLn hPutStrLn = \h -> liftIO . BL.hPutStrLn h
instance Print [Base.Char] where instance Print [Base.Char] where
putStr = liftIO . Base.putStr hPutStr = \h -> liftIO . Base.hPutStr h
putStrLn = liftIO . Base.putStrLn hPutStrLn = \h -> liftIO . Base.hPutStrLn h
-- For forcing type inference -- For forcing type inference
putText :: MonadIO m => T.Text -> m () putText :: MonadIO m => T.Text -> m ()