{-# LANGUAGE ExtendedDefaultRules #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude #-}

module Protolude.Show
  ( Print,
    hPutStr,
    putStr,
    hPutStrLn,
    putStrLn,
    putErrLn,
    putText,
    putErrText,
    putLText,
    putByteString,
    putLByteString,
  )
where

import Control.Monad.IO.Class (MonadIO, liftIO)
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.Function ((.))
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.IO as TL
import qualified Protolude.Base as Base
import qualified System.IO as Base
import System.IO (Handle, stderr, stdout)

class Print a where
  hPutStr :: MonadIO m => Handle -> a -> m ()
  putStr :: MonadIO m => a -> m ()
  putStr = Handle -> a -> m ()
forall a (m :: * -> *). (Print a, MonadIO m) => Handle -> a -> m ()
forall (m :: * -> *). MonadIO m => Handle -> a -> m ()
hPutStr Handle
stdout
  hPutStrLn :: MonadIO m => Handle -> a -> m ()
  putStrLn :: MonadIO m => a -> m ()
  putStrLn = Handle -> a -> m ()
forall a (m :: * -> *). (Print a, MonadIO m) => Handle -> a -> m ()
forall (m :: * -> *). MonadIO m => Handle -> a -> m ()
hPutStrLn Handle
stdout
  putErrLn :: MonadIO m => a -> m ()
  putErrLn = Handle -> a -> m ()
forall a (m :: * -> *). (Print a, MonadIO m) => Handle -> a -> m ()
forall (m :: * -> *). MonadIO m => Handle -> a -> m ()
hPutStrLn Handle
stderr

instance Print T.Text where
  hPutStr :: forall (m :: * -> *). MonadIO m => Handle -> Text -> m ()
hPutStr = \Handle
h -> IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (Text -> IO ()) -> Text -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Text -> IO ()
T.hPutStr Handle
h
  hPutStrLn :: forall (m :: * -> *). MonadIO m => Handle -> Text -> m ()
hPutStrLn = \Handle
h -> IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (Text -> IO ()) -> Text -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Text -> IO ()
T.hPutStrLn Handle
h

instance Print TL.Text where
  hPutStr :: forall (m :: * -> *). MonadIO m => Handle -> Text -> m ()
hPutStr = \Handle
h -> IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (Text -> IO ()) -> Text -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Text -> IO ()
TL.hPutStr Handle
h
  hPutStrLn :: forall (m :: * -> *). MonadIO m => Handle -> Text -> m ()
hPutStrLn = \Handle
h -> IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (Text -> IO ()) -> Text -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Text -> IO ()
TL.hPutStrLn Handle
h

instance Print BS.ByteString where
  hPutStr :: forall (m :: * -> *). MonadIO m => Handle -> ByteString -> m ()
hPutStr = \Handle
h -> IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (ByteString -> IO ()) -> ByteString -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ()
BS.hPutStr Handle
h
  hPutStrLn :: forall (m :: * -> *). MonadIO m => Handle -> ByteString -> m ()
hPutStrLn = \Handle
h -> IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (ByteString -> IO ()) -> ByteString -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ()
BS.hPutStrLn Handle
h

instance Print BL.ByteString where
  hPutStr :: forall (m :: * -> *). MonadIO m => Handle -> ByteString -> m ()
hPutStr = \Handle
h -> IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (ByteString -> IO ()) -> ByteString -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ()
BL.hPutStr Handle
h
  hPutStrLn :: forall (m :: * -> *). MonadIO m => Handle -> ByteString -> m ()
hPutStrLn = \Handle
h -> IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (ByteString -> IO ()) -> ByteString -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ()
BL.hPutStrLn Handle
h

instance Print [Base.Char] where
  hPutStr :: forall (m :: * -> *). MonadIO m => Handle -> [Char] -> m ()
hPutStr = \Handle
h -> IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> ([Char] -> IO ()) -> [Char] -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> [Char] -> IO ()
Base.hPutStr Handle
h
  hPutStrLn :: forall (m :: * -> *). MonadIO m => Handle -> [Char] -> m ()
hPutStrLn = \Handle
h -> IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> ([Char] -> IO ()) -> [Char] -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> [Char] -> IO ()
Base.hPutStrLn Handle
h

-- For forcing type inference
putText :: MonadIO m => T.Text -> m ()
putText :: forall (m :: * -> *). MonadIO m => Text -> m ()
putText = Text -> m ()
forall a (m :: * -> *). (Print a, MonadIO m) => a -> m ()
forall (m :: * -> *). MonadIO m => Text -> m ()
putStrLn
{-# SPECIALIZE putText :: T.Text -> Base.IO () #-}

putLText :: MonadIO m => TL.Text -> m ()
putLText :: forall (m :: * -> *). MonadIO m => Text -> m ()
putLText = Text -> m ()
forall a (m :: * -> *). (Print a, MonadIO m) => a -> m ()
forall (m :: * -> *). MonadIO m => Text -> m ()
putStrLn
{-# SPECIALIZE putLText :: TL.Text -> Base.IO () #-}

putByteString :: MonadIO m => BS.ByteString -> m ()
putByteString :: forall (m :: * -> *). MonadIO m => ByteString -> m ()
putByteString = ByteString -> m ()
forall a (m :: * -> *). (Print a, MonadIO m) => a -> m ()
forall (m :: * -> *). MonadIO m => ByteString -> m ()
putStrLn
{-# SPECIALIZE putByteString :: BS.ByteString -> Base.IO () #-}

putLByteString :: MonadIO m => BL.ByteString -> m ()
putLByteString :: forall (m :: * -> *). MonadIO m => ByteString -> m ()
putLByteString = ByteString -> m ()
forall a (m :: * -> *). (Print a, MonadIO m) => a -> m ()
forall (m :: * -> *). MonadIO m => ByteString -> m ()
putStrLn
{-# SPECIALIZE putLByteString :: BL.ByteString -> Base.IO () #-}

putErrText :: MonadIO m => T.Text -> m ()
putErrText :: forall (m :: * -> *). MonadIO m => Text -> m ()
putErrText = Text -> m ()
forall a (m :: * -> *). (Print a, MonadIO m) => a -> m ()
forall (m :: * -> *). MonadIO m => Text -> m ()
putErrLn
{-# SPECIALIZE putErrText :: T.Text -> Base.IO () #-}