Skip to content

Commit

Permalink
[serokell#186] Specialized file manipulations to IO
Browse files Browse the repository at this point in the history
  • Loading branch information
JustusAdam committed Oct 28, 2018
1 parent bc30001 commit ef660a4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Universum/Lifted/File.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Prelude (FilePath)
import System.IO (Handle, IOMode)

import qualified Data.Text.IO as XIO
import qualified System.IO as XIO (openFile, hClose)
import qualified System.IO as XIO (openFile, hClose, IO)

----------------------------------------------------------------------------
-- Text
Expand Down Expand Up @@ -63,4 +63,10 @@ hClose = liftIO . XIO.hClose
withFile :: (MonadIO m, MonadMask m) => FilePath -> IOMode -> (Handle -> m a) -> m a
withFile filePath mode f = bracket (openFile filePath mode) hClose f

-- 'withFile' can't be lifted into 'MonadIO', as it uses 'bracket'
{-# SPECIALIZE appendFile :: FilePath -> Text -> XIO.IO () #-}
{-# SPECIALIZE getLine :: XIO.IO Text #-}
{-# SPECIALIZE readFile :: FilePath -> XIO.IO Text #-}
{-# SPECIALIZE writeFile :: FilePath -> Text -> XIO.IO () #-}
{-# SPECIALIZE openFile :: FilePath -> IOMode -> XIO.IO Handle #-}
{-# SPECIALIZE hClose :: Handle -> XIO.IO () #-}
{-# SPECIALIZE withFile :: FilePath -> IOMode -> (Handle -> XIO.IO a) -> XIO.IO a #-}

0 comments on commit ef660a4

Please sign in to comment.