diff --git a/base-compat-batteries/CHANGES.markdown b/base-compat-batteries/CHANGES.markdown index f49ae99..e559643 100644 --- a/base-compat-batteries/CHANGES.markdown +++ b/base-compat-batteries/CHANGES.markdown @@ -1,3 +1,8 @@ +## Changes in ?.??.? [????.??.??] + - This coincides with the `base-compat-?.??.?` release. Refer to the + [`base-compat` changelog](https://github.com/haskell-compat/base-compat/blob/master/base-compat/CHANGES.markdown#changes-in-????-????????) + for more details. + ## Changes in 0.11.1 [2020.01.27] - This coincides with the `base-compat-0.11.1` release. Refer to the [`base-compat` changelog](https://github.com/haskell-compat/base-compat/blob/master/base-compat/CHANGES.markdown#changes-in-0111-20200127) diff --git a/base-compat-batteries/base-compat-batteries.cabal b/base-compat-batteries/base-compat-batteries.cabal index 7aaf3e9..feba959 100644 --- a/base-compat-batteries/base-compat-batteries.cabal +++ b/base-compat-batteries/base-compat-batteries.cabal @@ -144,6 +144,7 @@ library Prelude.Compat System.Environment.Compat System.Exit.Compat + System.IO.Compat System.IO.Error.Compat System.IO.Unsafe.Compat Text.Read.Compat @@ -203,6 +204,7 @@ library Prelude.Compat.Repl.Batteries System.Environment.Compat.Repl.Batteries System.Exit.Compat.Repl.Batteries + System.IO.Compat.Repl.Batteries System.IO.Error.Compat.Repl.Batteries System.IO.Unsafe.Compat.Repl.Batteries Text.Read.Compat.Repl.Batteries diff --git a/base-compat-batteries/src/Data/List/NonEmpty/Compat.hs b/base-compat-batteries/src/Data/List/NonEmpty/Compat.hs index abd298e..6cd458e 100644 --- a/base-compat-batteries/src/Data/List/NonEmpty/Compat.hs +++ b/base-compat-batteries/src/Data/List/NonEmpty/Compat.hs @@ -1,6 +1,4 @@ {-# LANGUAGE CPP, NoImplicitPrelude, PackageImports #-} --- | This backports the modern "Data.Semigroup" interface back to --- @base-4.9@/GHC 8.0. module Data.List.NonEmpty.Compat ( -- * The type of non-empty streams NonEmpty(..) @@ -21,6 +19,7 @@ module Data.List.NonEmpty.Compat ( , tail , last , init + , singleton , (<|), cons , uncons , unfoldr @@ -76,3 +75,11 @@ import "base-compat" Data.List.NonEmpty.Compat #else import "semigroups" Data.List.NonEmpty #endif + +#if !(MIN_VERSION_base(4,9,0)) +-- | Construct a 'NonEmpty' list from a single element. +-- +-- /Since: 4.15/ +singleton :: a -> NonEmpty a +singleton a = a :| [] +#endif diff --git a/base-compat-batteries/src/System/IO/Compat.hs b/base-compat-batteries/src/System/IO/Compat.hs new file mode 100644 index 0000000..2e08085 --- /dev/null +++ b/base-compat-batteries/src/System/IO/Compat.hs @@ -0,0 +1,6 @@ +{-# LANGUAGE CPP, NoImplicitPrelude, PackageImports #-} +module System.IO.Compat ( + module Base +) where + +import "base-compat" System.IO.Compat as Base diff --git a/base-compat-batteries/src/System/IO/Compat/Repl/Batteries.hs b/base-compat-batteries/src/System/IO/Compat/Repl/Batteries.hs new file mode 100644 index 0000000..59ea46a --- /dev/null +++ b/base-compat-batteries/src/System/IO/Compat/Repl/Batteries.hs @@ -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 diff --git a/base-compat/CHANGES.markdown b/base-compat/CHANGES.markdown index 052b5d3..78e0159 100644 --- a/base-compat/CHANGES.markdown +++ b/base-compat/CHANGES.markdown @@ -1,3 +1,8 @@ +## Changes in ?.??.?? [????.??.??] + - Sync with `base-4.15`/GHC 9.0 + - Backport `singleton` to `Data.List` and `Data.List.NonEmpty` + - Backport `hGetContents'`, `getContents'`, and `readFile'` added to `System.IO` + ## Changes in 0.11.1 [2020.01.27] - Sync with `base-4.14`/GHC 8.10 - Backport `isResourceVanishedError`, `resourceVanishedErrorType`, and diff --git a/base-compat/README.markdown b/base-compat/README.markdown index 31e70c5..6277a62 100644 --- a/base-compat/README.markdown +++ b/base-compat/README.markdown @@ -152,6 +152,8 @@ So far the following is covered. * `RuntimeRep`-polymorphic `throw` to `Control.Exception.Compat` * `isResourceVanishedError`, `resourceVanishedErrorType`, and `isResourceVanishedErrorType` to `System.IO.Error.Compat` + * `singleton` to `Data.List.Compat` and `Data.List.NonEmpty.Compat` + * `hGetContents'`, `getContents'`, and `readFile'` to `System.IO` ## What is not covered @@ -304,6 +306,7 @@ on, paired with the things that each library backports: ## Supported versions of GHC/`base` + * `ghc-9.0.*` / `base-4.15.*` * `ghc-8.10.*` / `base-4.14.*` * `ghc-8.8.*` / `base-4.13.*` * `ghc-8.6.*` / `base-4.12.*` diff --git a/base-compat/base-compat.cabal b/base-compat/base-compat.cabal index b2b9988..191f18d 100644 --- a/base-compat/base-compat.cabal +++ b/base-compat/base-compat.cabal @@ -134,6 +134,7 @@ library Prelude.Compat System.Environment.Compat System.Exit.Compat + System.IO.Compat System.IO.Error.Compat System.IO.Unsafe.Compat Text.Read.Compat @@ -193,6 +194,7 @@ library Prelude.Compat.Repl System.Environment.Compat.Repl System.Exit.Compat.Repl + System.IO.Compat.Repl System.IO.Error.Compat.Repl System.IO.Unsafe.Compat.Repl Text.Read.Compat.Repl diff --git a/base-compat/src/Data/List/Compat.hs b/base-compat/src/Data/List/Compat.hs index 2f54df5..fa5c9e6 100644 --- a/base-compat/src/Data/List/Compat.hs +++ b/base-compat/src/Data/List/Compat.hs @@ -5,6 +5,10 @@ #endif module Data.List.Compat ( module Base +#if !(MIN_VERSION_base(4,15,0)) +, singleton +#endif + #if !(MIN_VERSION_base(4,11,0)) , iterate' #endif @@ -235,3 +239,15 @@ iterate'FB c f x0 = go x0 "iterate'FB" [1] iterate'FB (:) = iterate' #-} #endif + +#if !(MIN_VERSION_base(4,15,0)) +-- | Produce singleton list. +-- +-- >>> singleton True +-- [True] +-- +-- /Since: 4.14.0.0/ +-- +singleton :: a -> [a] +singleton x = [x] +#endif diff --git a/base-compat/src/Data/List/NonEmpty/Compat.hs b/base-compat/src/Data/List/NonEmpty/Compat.hs index 89c8dea..4f911d8 100644 --- a/base-compat/src/Data/List/NonEmpty/Compat.hs +++ b/base-compat/src/Data/List/NonEmpty/Compat.hs @@ -22,6 +22,7 @@ module Data.List.NonEmpty.Compat ( , tail , last , init + , singleton , (<|), cons , uncons , unfoldr @@ -76,3 +77,11 @@ module Data.List.NonEmpty.Compat ( #if MIN_VERSION_base(4,9,0) import Data.List.NonEmpty #endif + +#if MIN_VERSION_base(4,9,0) && !(MIN_VERSION_base(4,15,0)) +-- | Construct a 'NonEmpty' list from a single element. +-- +-- /Since: 4.15/ +singleton :: a -> NonEmpty a +singleton a = a :| [] +#endif diff --git a/base-compat/src/System/IO/Compat.hs b/base-compat/src/System/IO/Compat.hs new file mode 100644 index 0000000..1b39c02 --- /dev/null +++ b/base-compat/src/System/IO/Compat.hs @@ -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 diff --git a/base-compat/src/System/IO/Compat/Repl.hs b/base-compat/src/System/IO/Compat/Repl.hs new file mode 100644 index 0000000..939125b --- /dev/null +++ b/base-compat/src/System/IO/Compat/Repl.hs @@ -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