-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport functions introduced in base-4.15
Checks off the `base-4.15.0.0` boxes in #24.
- Loading branch information
1 parent
32b9028
commit b103647
Showing
12 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{-# LANGUAGE CPP, NoImplicitPrelude, PackageImports #-} | ||
module System.IO.Compat ( | ||
module Base | ||
) where | ||
|
||
import "base-compat" System.IO.Compat as Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{-# LANGUAGE PackageImports #-} | ||
{-# OPTIONS_GHC -fno-warn-dodgy-exports -fno-warn-unused-imports #-} | ||
-- | Reexports "System.IO.Compat" | ||
-- from a globally unique namespace. | ||
module System.IO.Compat.Repl.Batteries ( | ||
module System.IO.Compat | ||
) where | ||
import "this" System.IO.Compat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{-# LANGUAGE CPP, NoImplicitPrelude #-} | ||
module System.IO.Compat ( | ||
module Base | ||
, getContents' | ||
, hGetContents' | ||
, readFile' | ||
) where | ||
|
||
import System.IO as Base | ||
|
||
#if !(MIN_VERSION_base(4,15,0)) | ||
import Prelude.Compat | ||
|
||
-- | The 'getContents'' operation returns all user input as a single string, | ||
-- which is fully read before being returned | ||
-- (same as 'hGetContents'' 'stdin'). | ||
-- | ||
-- /Since: 4.15.0.0/ | ||
|
||
getContents' :: IO String | ||
getContents' = hGetContents' stdin | ||
|
||
-- | The 'readFile'' function reads a file and | ||
-- returns the contents of the file as a string. | ||
-- The file is fully read before being returned, as with 'getContents''. | ||
-- | ||
-- /Since: 4.15.0.0/ | ||
|
||
readFile' :: FilePath -> IO String | ||
readFile' name = openFile name ReadMode >>= hGetContents' | ||
|
||
-- | The 'hGetContents'' operation reads all input on the given handle | ||
-- before returning it as a 'String' and closing the handle. | ||
-- | ||
-- /Since: 4.15.0.0/ | ||
|
||
hGetContents' :: Handle -> IO String | ||
hGetContents' h = hGetContents h >>= \s -> length s `seq` return s | ||
-- NB: The actual implementation of hGetContents' in `base` uses a lot of | ||
-- low-level code from GHC.IO.Handle.Text. What's worse, a lot of this | ||
-- low-level code isn't exported, so we'd have to reimplement large chunks | ||
-- of it in base-compat if we wanted to backport it. For now, I've opted for | ||
-- the simpler approach of simply defining hGetContents' in terms of | ||
-- hGetContents, which is the approach that the `extra` and `strict` libraries | ||
-- use. (Indeed, the code above is taken from `strict`.) | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{-# LANGUAGE PackageImports #-} | ||
{-# OPTIONS_GHC -fno-warn-dodgy-exports -fno-warn-unused-imports #-} | ||
-- | Reexports "System.IO.Compat" | ||
-- from a globally unique namespace. | ||
module System.IO.Compat.Repl ( | ||
module System.IO.Compat | ||
) where | ||
import "this" System.IO.Compat |