base-compat 0.9.2 → 0.9.3
raw patch · 9 files changed
+182/−4 lines, 9 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Either.Compat: fromLeft :: a -> Either a b -> a
+ Data.Either.Compat: fromRight :: b -> Either a b -> b
+ Data.Foldable.Compat: maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
+ Data.Foldable.Compat: minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
+ Data.Proxy.Compat: asProxyTypeOf :: a -> proxy a -> a
+ Data.Type.Coercion.Compat: gcoerceWith :: Coercion a b -> (Coercible a b => r) -> r
+ Foreign.ForeignPtr.Compat: plusForeignPtr :: ForeignPtr a -> Int -> ForeignPtr b
Files
- CHANGES.markdown +10/−0
- README.markdown +12/−3
- base-compat.cabal +6/−1
- src/Data/Either/Compat.hs +38/−0
- src/Data/Foldable/Compat.hs +27/−0
- src/Data/Proxy/Compat.hs +27/−0
- src/Data/Type/Coercion/Compat.hs +22/−0
- src/Foreign/ForeignPtr/Compat.hs +27/−0
- test/Data/Foldable/CompatSpec.hs +13/−0
CHANGES.markdown view
@@ -1,3 +1,13 @@+## Changes in 0.9.3 [2017.04.10]+ - Sync with `base-4.10`/GHC 8.2+ - Backport `fromLeft`/`fromRight` to `Data.Either.Compat`+ - Backport implementations of `maximumBy`/`minimumBy` which use constant stack+ space to `Data.Foldable.Compat`+ - Backport `asProxyTypeOf` with a generalized type signature to+ `Data.Proxy.Compat`+ - Backport `gcoerceWith` to `Data.Type.Coercion.Compat`+ - Backport `plusForeignPtr` to `Foreign.ForeignPtr.Compat`+ ## Changes in 0.9.2 - Allow building on the HaLVM
README.markdown view
@@ -114,23 +114,27 @@ * Added `bitDefault`, `testBitDefault`, and `popCountDefault` to `Data.Bits.Compat` * Added `toIntegralSized` to `Data.Bits.Compat` (if using `base-4.7`) * Added `bool` function to `Data.Bool.Compat`- * Added `isLeft` and `isRight` to `Data.Either.Compat`+ * Added `isLeft`, `isRight`, `fromLeft`, and `fromRight` to `Data.Either.Compat` * Added `forkFinally` to `Control.Concurrent.Compat` * Added `withMVarMasked` function to `Control.Concurrent.MVar.Compat` * Added `(<$!>)` function to `Control.Monad.Compat` * Weakened `RealFloat` constraints on `realPart`, `imagPart`, `conjugate`, `mkPolar`, and `cis` in `Data.Complex.Compat`+ * Added more efficient `maximumBy`/`minimumBy` to `Data.Foldable.Compat` * Added `($>)` and `void` functions to `Data.Functor.Compat` * `(&)` function to `Data.Function.Compat` * `($>)` and `void` functions to `Data.Functor.Compat` * `modifyIORef'`, `atomicModifyIORef'` and `atomicWriteIORef` to `Data.IORef.Compat` * `dropWhileEnd`, `isSubsequenceOf`, `sortOn`, and `uncons` functions to `Data.List.Compat` * Correct versions of `nub`, `nubBy`, `union`, and `unionBy` to `Data.List.Compat`+ * `asProxyTypeOf` with a generalized type signature to `Data.Proxy.Compat` * `modifySTRef'` to `Data.STRef.Compat` * `String`, `lines`, `words`, `unlines`, and `unwords` to `Data.String.Compat`+ * `gcoerceWith` to `Data.Type.Coercion.Compat` * `makeVersion` function to `Data.Version.Compat` * `traceId`, `traceShowId`, `traceM`, and `traceShowM` functions to `Debug.Trace.Compat` * `byteSwap16`, `byteSwap32`, and `byteSwap64` to `Data.Word.Compat`+ * `plusForeignPtr` to `Foreign.ForeignPtr.Compat` * `calloc` and `callocBytes` functions to `Foreign.Marshal.Alloc.Compat` * `callocArray` and `callocArray0` functions to `Foreign.Marshal.Array.Compat` * `fillBytes` to `Foreign.Marshal.Utils.Compat`@@ -192,8 +196,12 @@ compatibility packages on Hackage. Here is a list of such packages: * [`bifunctors`](http://hackage.haskell.org/package/bifunctors)- for the [`Bifunctor`](http://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Bifunctor.html#t:Bifunctor)- type class, introduced in `base-4.8.0.0`+ for:+ * The [`Bifunctor`](http://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Bifunctor.html#t:Bifunctor)+ type class, introduced in `base-4.8.0.0`+ * The [`Bifoldable`](http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Bifoldable.html#t:Bifoldable)+ and [`Bitraversable`](http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Bitraversable.html#t:Bitraversable)+ type classes, introduced in `base-4.10.0.0` * [`fail`](http://hackage.haskell.org/package/fail) for the [`MonadFail`](http://hackage.haskell.org/package/base-4.9.0.0/docs/Control-Monad-Fail.html#t:MonadFail) type class, introduced in `base-4.9.0.0`@@ -245,6 +253,7 @@ ## Supported versions of GHC/`base` + * `ghc-8.2.1` / `base-4.10.0.0` * `ghc-8.0.2` / `base-4.9.1.0` * `ghc-8.0.1` / `base-4.9.0.0` * `ghc-7.10.3` / `base-4.8.2.0`
base-compat.cabal view
@@ -1,5 +1,5 @@ name: base-compat-version: 0.9.2+version: 0.9.3 license: MIT license-file: LICENSE copyright: (c) 2012-2017 Simon Hengel,@@ -39,6 +39,7 @@ , GHC == 7.8.1, GHC == 7.8.2, GHC == 7.8.3, GHC == 7.8.4 , GHC == 7.10.1, GHC == 7.10.2, GHC == 7.10.3 , GHC == 8.0.1, GHC == 8.0.2+ , GHC == 8.2.1 extra-source-files: CHANGES.markdown, README.markdown source-repository head@@ -75,13 +76,16 @@ Data.IORef.Compat Data.List.Compat Data.Monoid.Compat+ Data.Proxy.Compat Data.Ratio.Compat Data.STRef.Compat Data.String.Compat+ Data.Type.Coercion.Compat Data.Version.Compat Data.Word.Compat Debug.Trace.Compat Foreign.Compat+ Foreign.ForeignPtr.Compat Foreign.ForeignPtr.Safe.Compat Foreign.ForeignPtr.Unsafe.Compat Foreign.Marshal.Alloc.Compat@@ -111,6 +115,7 @@ Data.Bits.CompatSpec Data.Bool.CompatSpec Data.Either.CompatSpec+ Data.Foldable.CompatSpec Data.Function.CompatSpec Data.Functor.CompatSpec Data.IORef.CompatSpec
src/Data/Either/Compat.hs view
@@ -3,6 +3,8 @@ module Base , isLeft , isRight+, fromLeft+, fromRight ) where import Data.Either as Base @@ -22,4 +24,40 @@ isRight :: Either a b -> Bool isRight (Left _) = False isRight (Right _) = True+#endif++#if !(MIN_VERSION_base(4,10,0))+-- | Return the contents of a 'Left'-value or a default value otherwise.+--+-- /Since: 4.10.0.0/+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> fromLeft 1 (Left 3)+-- 3+-- >>> fromLeft 1 (Right "foo")+-- 1+--+fromLeft :: a -> Either a b -> a+fromLeft _ (Left a) = a+fromLeft a _ = a++-- | Return the contents of a 'Right'-value or a default value otherwise.+--+-- /Since: 4.10.0.0/+--+-- ==== __Examples__+--+-- Basic usage:+--+-- >>> fromRight 1 (Right 3)+-- 3+-- >>> fromRight 1 (Left "foo")+-- 1+--+fromRight :: b -> Either a b -> b+fromRight _ (Right b) = b+fromRight b _ = b #endif
src/Data/Foldable/Compat.hs view
@@ -5,9 +5,18 @@ , length , null #endif+#if !(MIN_VERSION_base(4,10,0))+, maximumBy+, minimumBy+#endif ) where +#if MIN_VERSION_base(4,10,0) import Data.Foldable as Base+#else+import Data.Foldable as Base hiding (maximumBy, minimumBy)+import Prelude (Ordering(..))+#endif #if !(MIN_VERSION_base(4,8,0)) import Prelude (Bool(..), Int, (+))@@ -23,4 +32,22 @@ -- cons-lists, because there is no general way to do better. length :: Foldable t => t a -> Int length = foldl' (\c _ -> c+1) 0+#endif++#if !(MIN_VERSION_base(4,10,0))+-- | The largest element of a non-empty structure with respect to the+-- given comparison function.+maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a+maximumBy cmp = foldl1 max'+ where max' x y = case cmp x y of+ GT -> x+ _ -> y++-- | The least element of a non-empty structure with respect to the+-- given comparison function.+minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a+minimumBy cmp = foldl1 min'+ where min' x y = case cmp x y of+ GT -> y+ _ -> x #endif
+ src/Data/Proxy/Compat.hs view
@@ -0,0 +1,27 @@+{-# LANGUAGE CPP, NoImplicitPrelude #-}+module Data.Proxy.Compat (+#if MIN_VERSION_base(4,7,0)+ module Base,+#endif+ asProxyTypeOf+) where++#if MIN_VERSION_base(4,7,0)+# if MIN_VERSION_base(4,10,0)+import Data.Proxy as Base+# else+import Data.Proxy as Base hiding (asProxyTypeOf)+# endif+#endif++#if !(MIN_VERSION_base(4,10,0))+import Prelude (const)++-- | 'asProxyTypeOf' is a type-restricted version of 'const'.+-- It is usually used as an infix operator, and its typing forces its first+-- argument (which is usually overloaded) to have the same type as the tag+-- of the second.+asProxyTypeOf :: a -> proxy a -> a+asProxyTypeOf = const+{-# INLINE asProxyTypeOf #-}+#endif
+ src/Data/Type/Coercion/Compat.hs view
@@ -0,0 +1,22 @@+{-# LANGUAGE CPP, NoImplicitPrelude #-}+{-# LANGUAGE RankNTypes #-}+module Data.Type.Coercion.Compat (+#if MIN_VERSION_base(4,7,0)+ module Base+, gcoerceWith+#endif+) where++#if MIN_VERSION_base(4,7,0)+import Data.Type.Coercion as Base++# if !(MIN_VERSION_base(4,10,0))+import Data.Coerce (Coercible)++-- | Generalized form of type-safe cast using representational equality+--+-- /Since: 4.10.0.0/+gcoerceWith :: Coercion a b -> (Coercible a b => r) -> r+gcoerceWith Coercion x = x+# endif+#endif
+ src/Foreign/ForeignPtr/Compat.hs view
@@ -0,0 +1,27 @@+{-# LANGUAGE CPP, NoImplicitPrelude #-}+{-# LANGUAGE MagicHash #-}+module Foreign.ForeignPtr.Compat (+ module Base+, plusForeignPtr+) where++import Foreign.ForeignPtr as Base++#if !(MIN_VERSION_base(4,10,0))+import GHC.Exts (Int(..), plusAddr#)+import GHC.ForeignPtr (ForeignPtr(..))++plusForeignPtr :: ForeignPtr a -> Int -> ForeignPtr b+-- ^Advances the given address by the given offset in bytes.+--+-- The new 'ForeignPtr' shares the finalizer of the original,+-- equivalent from a finalization standpoint to just creating another+-- reference to the original. That is, the finalizer will not be+-- called before the new 'ForeignPtr' is unreachable, nor will it be+-- called an additional time due to this call, and the finalizer will+-- be called with the same address that it would have had this call+-- not happened, *not* the new address.+--+-- /Since: 4.10.0.0/+plusForeignPtr (ForeignPtr addr c) (I# d) = ForeignPtr (plusAddr# addr d) c+#endif
+ test/Data/Foldable/CompatSpec.hs view
@@ -0,0 +1,13 @@+module Data.Foldable.CompatSpec (main, spec) where++import Test.Hspec+import Data.Foldable.Compat++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+ describe "maximumBy" $ do+ it "runs in constant space" $ do+ maximumBy compare [1..10000] `shouldBe` (10000 :: Int)