base-compat 0.13.0 → 0.13.1
raw patch · 9 files changed
+186/−4 lines, 9 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Functor.Compat: unzip :: Functor f => f (a, b) -> (f a, f b)
+ Data.List.Compat: (!?) :: [a] -> Int -> Maybe a
+ Data.List.Compat: infixl 9 !?
+ Data.List.Compat: unsnoc :: [a] -> Maybe ([a], a)
+ Data.Tuple.Compat: getSolo :: Solo a -> a
+ Data.Typeable.Compat: decT :: forall a b. (Typeable a, Typeable b) => Either ((a :~: b) -> Void) (a :~: b)
+ Data.Typeable.Compat: hdecT :: forall a b. (Typeable a, Typeable b) => Either ((a :~~: b) -> Void) (a :~~: b)
+ Type.Reflection.Compat: decTypeRep :: forall k1 k2 (a :: k1) (b :: k2). TypeRep a -> TypeRep b -> Either ((a :~~: b) -> Void) (a :~~: b)
Files
- CHANGES.markdown +15/−0
- README.markdown +6/−0
- base-compat.cabal +18/−1
- src/Data/Functor/Compat.hs +13/−0
- src/Data/List/Compat.hs +70/−0
- src/Data/Tuple/Compat.hs +7/−0
- src/Data/Typeable/Compat.hs +29/−3
- src/Prelude/Compat.hs +2/−0
- src/Type/Reflection/Compat.hs +26/−0
CHANGES.markdown view
@@ -1,3 +1,13 @@+## Changes in 0.13.1 [2023.10.11]+ - Sync with `base-4.19`/GHC 9.8+ - Backport `unzip` to `Data.Functor.Compat`+ - Backport `(!?)` and `unsnoc` to `Data.List.Compat`+ - Backport `getSolo` to `Data.Tuple.Compat` when building against+ `ghc-prim-0.8.0` (GHC 9.2) or later. To backport `getSolo` to older versions+ of GHC, import `Data.Tuple.Compat` from `base-compat-batteries` instead.+ - Backport `decT` and `hdecT` to `Data.Typeable.Compat`+ - Backport `decTypeRep` to `Type.Reflection.Compat`+ ## Changes in 0.13.0 [2023.03.10] - Sync with `base-4.18`/GHC 9.6 - Backport `liftA2` being re-exported from `Prelude.Compat`.@@ -22,6 +32,11 @@ which correspond to changes made in `base-4.18.0.0`. You may consider using `base-compat-batteries` instead if you want increase the range of `base` versions that are supported.++## Changes in 0.12.3 [2023.07.12]+ - This coincides with the `base-compat-batteries-0.12.3` release. Refer to the+ [`base-compat-batteries` changelog](https://github.com/haskell-compat/base-compat/blob/master/base-compat-batteries/CHANGES.markdown#changes-in-0123-20230712)+ for more details. ## Changes in 0.12.2 [2022.08.11] - Sync with `base-4.17`/GHC 9.4
README.markdown view
@@ -163,6 +163,11 @@ * `minusNaturalMaybe` to `Numeric.Natural.Compat` * `mapAccumM` and `forAccumM` to `Data.Traversable.Compat` * `heqT` to `Data.Typeable.Compat`+ * `unzip` to `Data.Functor.Compat`+ * `(!?)` and `unsnoc` to `Data.List.Compat`+ * `getSolo` to `Data.Tuple.Compat`+ * `decT` and `hdecT` to `Data.Typeable.Compat`+ * `decTypeRep` to `Type.Reflection.Compat` ## What is not covered @@ -340,6 +345,7 @@ ## Supported versions of GHC/`base` + * `ghc-9.8.*` / `base-4.19.*` * `ghc-9.6.*` / `base-4.18.*` * `ghc-9.4.*` / `base-4.17.*` * `ghc-9.2.*` / `base-4.16.*`
base-compat.cabal view
@@ -1,5 +1,5 @@ name: base-compat-version: 0.13.0+version: 0.13.1 license: MIT license-file: LICENSE copyright: (c) 2012-2018 Simon Hengel,@@ -44,6 +44,23 @@ anything in @base-compat-batteries@, to allow for easier use in GHCi. extra-source-files: CHANGES.markdown, README.markdown+tested-with: GHC == 7.0.4+ , GHC == 7.2.2+ , GHC == 7.4.2+ , GHC == 7.6.3+ , GHC == 7.8.4+ , GHC == 7.10.3+ , GHC == 8.0.2+ , GHC == 8.2.2+ , GHC == 8.4.4+ , GHC == 8.6.5+ , GHC == 8.8.4+ , GHC == 8.10.7+ , GHC == 9.0.2+ , GHC == 9.2.7+ , GHC == 9.4.5+ , GHC == 9.6.2+ , GHC == 9.8.1 source-repository head type: git
src/Data/Functor/Compat.hs view
@@ -5,6 +5,7 @@ , ($>) , void , (<&>)+, unzip ) where import Data.Functor as Base @@ -13,6 +14,10 @@ import Data.Function (flip) #endif +#if !(MIN_VERSION_base(4,19,0))+import Data.Tuple (fst, snd)+#endif+ #if !(MIN_VERSION_base(4,7,0)) infixl 4 $> @@ -48,4 +53,12 @@ as <&> f = f <$> as infixl 1 <&>+#endif++#if !(MIN_VERSION_base(4,19,0))+-- | Generalization of @Data.List.@'Data.List.unzip'.+--+-- /Since: 4.19.0.0/+unzip :: Functor f => f (a, b) -> (f a, f b)+unzip xs = (fst <$> xs, snd <$> xs) #endif
src/Data/List/Compat.hs view
@@ -5,6 +5,11 @@ #endif module Data.List.Compat ( module Base+#if !(MIN_VERSION_base(4,19,0))+, (!?)+, unsnoc+#endif+ #if !(MIN_VERSION_base(4,15,0)) , singleton #endif@@ -94,6 +99,9 @@ #if !(MIN_VERSION_base(4,11,0)) import GHC.Exts (build)+#endif++#if !(MIN_VERSION_base(4,19,0)) import Prelude.Compat hiding (foldr, null) #endif @@ -250,4 +258,66 @@ -- singleton :: a -> [a] singleton x = [x]+#endif++#if !(MIN_VERSION_base(4,19,0))+infixl 9 !?+-- | List index (subscript) operator, starting from 0. Returns 'Nothing'+-- if the index is out of bounds+--+-- >>> ['a', 'b', 'c'] !? 0+-- Just 'a'+-- >>> ['a', 'b', 'c'] !? 2+-- Just 'c'+-- >>> ['a', 'b', 'c'] !? 3+-- Nothing+-- >>> ['a', 'b', 'c'] !? (-1)+-- Nothing+--+-- This is the total variant of the partial '!!' operator.+--+-- WARNING: This function takes linear time in the index.+(!?) :: [a] -> Int -> Maybe a++{-# INLINABLE (!?) #-}+xs !? n+ | n < 0 = Nothing+ | otherwise = foldr (\x r k -> case k of+ 0 -> Just x+ _ -> r (k-1)) (const Nothing) xs n++-- | \(\mathcal{O}(n)\). Decompose a list into 'init' and 'last'.+--+-- * If the list is empty, returns 'Nothing'.+-- * If the list is non-empty, returns @'Just' (xs, x)@,+-- where @xs@ is the 'init'ial part of the list and @x@ is its 'last' element.+--+-- /Since: 4.19.0.0/+--+-- >>> unsnoc []+-- Nothing+-- >>> unsnoc [1]+-- Just ([],1)+-- >>> unsnoc [1, 2, 3]+-- Just ([1,2],3)+--+-- Laziness:+--+-- >>> fst <$> unsnoc [undefined]+-- Just []+-- >>> head . fst <$> unsnoc (1 : undefined)+-- Just *** Exception: Prelude.undefined+-- >>> head . fst <$> unsnoc (1 : 2 : undefined)+-- Just 1+--+-- 'unsnoc' is dual to 'uncons': for a finite list @xs@+--+-- > unsnoc xs = (\(hd, tl) -> (reverse tl, hd)) <$> uncons (reverse xs)+--+unsnoc :: [a] -> Maybe ([a], a)+-- The lazy pattern ~(a, b) is important to be productive on infinite lists+-- and not to be prone to stack overflows.+-- Expressing the recursion via 'foldr' provides for list fusion.+unsnoc = foldr (\x -> Just . maybe ([], x) (\(~(a, b)) -> (x : a, b))) Nothing+{-# INLINABLE unsnoc #-} #endif
src/Data/Tuple/Compat.hs view
@@ -20,10 +20,17 @@ #elif MIN_VERSION_ghc_prim(0,7,0) , Solo(Solo) #endif+#if MIN_VERSION_ghc_prim(0,8,0)+ , getSolo+#endif ) where import Data.Tuple #if !(MIN_VERSION_base(4,16,0)) && MIN_VERSION_ghc_prim(0,7,0) import GHC.Tuple (Solo(..))+#endif++#if MIN_VERSION_ghc_prim(0,8,0) && !(MIN_VERSION_ghc_prim(0,11,0))+import GHC.Tuple (getSolo) #endif
src/Data/Typeable/Compat.hs view
@@ -2,27 +2,33 @@ #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} #endif-#if MIN_VERSION_base(4,10,0) && !(MIN_VERSION_base(4,18,0))+#if MIN_VERSION_base(4,10,0) && !(MIN_VERSION_base(4,19,0))+{-# LANGUAGE GADTs #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} #endif module Data.Typeable.Compat ( module Base #if MIN_VERSION_base(4,10,0) , heqT+, decT+, hdecT #endif ) where import Data.Typeable as Base -#if MIN_VERSION_base(4,10,0) && !(MIN_VERSION_base(4,18,0))+#if MIN_VERSION_base(4,10,0) && !(MIN_VERSION_base(4,19,0)) import Prelude.Compat +import Data.Void (Void) import qualified Type.Reflection.Compat as TR #endif -#if MIN_VERSION_base(4,10,0) && !(MIN_VERSION_base(4,18,0))+#if MIN_VERSION_base(4,10,0)+# if !(MIN_VERSION_base(4,18,0)) -- | Extract a witness of heterogeneous equality of two types -- -- /Since: 4.18.0.0/@@ -31,4 +37,24 @@ where ta = TR.typeRep :: TR.TypeRep a tb = TR.typeRep :: TR.TypeRep b+# endif++# if !(MIN_VERSION_base(4,19,0))+-- | Decide an equality of two types+--+-- /Since: 4.19.0.0/+decT :: forall a b. (Typeable a, Typeable b) => Either (a :~: b -> Void) (a :~: b)+decT = case hdecT @a @b of+ Right HRefl -> Right Refl+ Left p -> Left (\Refl -> p HRefl)++-- | Decide heterogeneous equality of two types.+--+-- /Since: 4.19.0.0/+hdecT :: forall a b. (Typeable a, Typeable b) => Either (a :~~: b -> Void) (a :~~: b)+hdecT = ta `TR.decTypeRep` tb+ where+ ta = TR.typeRep :: TR.TypeRep a+ tb = TR.typeRep :: TR.TypeRep b+# endif #endif
src/Prelude/Compat.hs view
@@ -295,7 +295,9 @@ # endif ) +# if !(MIN_VERSION_base(4,18,0)) import Control.Applicative (liftA2)+# endif #else
src/Type/Reflection/Compat.hs view
@@ -8,6 +8,7 @@ {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} # if !(MIN_VERSION_base(4,11,0)) {-# LANGUAGE TypeInType #-}@@ -18,6 +19,7 @@ module Base , withTypeable , pattern TypeRep+, decTypeRep #endif ) where @@ -31,8 +33,16 @@ # if !(MIN_VERSION_base(4,11,0)) import GHC.Exts (TYPE) import Type.Reflection (Typeable, TypeRep)+# endif++# if !(MIN_VERSION_base(4,19,0))+import Data.Void (Void)+import Prelude.Compat+import Type.Reflection.Unsafe (typeRepFingerprint) import Unsafe.Coerce (unsafeCoerce)+# endif +# if !(MIN_VERSION_base(4,11,0)) -- | Use a 'TypeRep' as 'Typeable' evidence. withTypeable :: forall (a :: k) (r :: TYPE rep). () => TypeRep a -> (Typeable a => r) -> r@@ -78,5 +88,21 @@ pattern TypeRep :: forall a. () => Typeable a => TypeRep a pattern TypeRep <- (typeableInstance -> TypeableInstance) where TypeRep = typeRep+# endif++# if !(MIN_VERSION_base(4,19,0))+-- | Type equality decision+--+-- /Since: 4.19.0.0/+decTypeRep :: forall k1 k2 (a :: k1) (b :: k2).+ TypeRep a -> TypeRep b -> Either (a :~~: b -> Void) (a :~~: b)+decTypeRep a b+ | sameTypeRep a b = Right (unsafeCoerce HRefl)+ | otherwise = Left (\HRefl -> errorWithoutStackTrace ("decTypeRep: Impossible equality proof " ++ show a ++ " :~: " ++ show b))+{-# INLINEABLE decTypeRep #-}++sameTypeRep :: forall k1 k2 (a :: k1) (b :: k2).+ TypeRep a -> TypeRep b -> Bool+sameTypeRep a b = typeRepFingerprint a == typeRepFingerprint b # endif #endif