Commits

Bryan O'Sullivan  committed e01b98f

Allow print and hprint to operate in any MonadIO

  • Participants
  • Parent commits a8ee136

Comments (0)

Files changed (2)

File Data/Text/Format.hs

     , fixed_
     ) where
 
-import qualified Data.Text.Buildable as B
+import Control.Monad.IO.Class (MonadIO(liftIO))
+import Data.Text.Format.Functions ((<>))
 import Data.Text.Format.Params (Params(..))
-import Data.Text.Format.Functions ((<>))
 import Data.Text.Format.Types.Internal (FPControl(..), FPFormat(..), Fast(..))
 import Data.Text.Format.Types.Internal (Format(..), Hex(..), Only(..), Shown(..))
 import Data.Text.Lazy.Builder
 import Prelude hiding (exp, print)
 import System.IO (Handle)
 import qualified Data.Text as ST
+import qualified Data.Text.Buildable as B
 import qualified Data.Text.Lazy as LT
 import qualified Data.Text.Lazy.IO as LT
 
 format fmt ps = toLazyText $ build fmt ps
 
 -- | Render a format string and arguments, then print the result.
-print :: Params ps => Format -> ps -> IO ()
-print fmt ps = LT.putStr . toLazyText $ build fmt ps
+print :: (MonadIO m, Params ps) => Format -> ps -> m ()
+{-# SPECIALIZE print :: (Params ps) => Format -> ps -> IO () #-}
+print fmt ps = liftIO . LT.putStr . toLazyText $ build fmt ps
 
 -- | Render a format string and arguments, then print the result to
 -- the given file handle.
-hprint :: Params ps => Handle -> Format -> ps -> IO ()
-hprint h fmt ps = LT.hPutStr h . toLazyText $ build fmt ps
+hprint :: (MonadIO m, Params ps) => Handle -> Format -> ps -> m ()
+{-# SPECIALIZE hprint :: (Params ps) => Handle -> Format -> ps -> IO () #-}
+hprint h fmt ps = liftIO . LT.hPutStr h . toLazyText $ build fmt ps
 
 -- | Pad the left hand side of a string until it reaches @k@
 -- characters wide, if necessary filling with character @c@.

File text-format.cabal

     integer-gmp,
     old-locale,
     text >= 0.11.0.8,
-    time
+    time,
+    transformers
 
   if flag(developer)
     ghc-options: -Werror