packages feed

base-orphans 0.5.0 → 0.5.1

raw patch · 5 files changed

+24/−18 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGES.markdown view
@@ -1,3 +1,8 @@+## Changes in 0.5.1+ - The `Storable` instances for `Complex` and `Ratio` are now exactly as lazy+   as their counterparts in `base` (see issue+   [#36](https://github.com/haskell-compat/base-orphans/issues/36))+ ## Changes in 0.5.0  - GHC 8.0 compatibility  - Backported instances introduced in GHC 8.0/`base-4.9`
base-orphans.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:                base-orphans-version:             0.5.0+version:             0.5.1 synopsis:            Backwards-compatible orphan instances for base description:         @base-orphans@ defines orphan instances that mimic instances available in later versions of @base@ to a wider (older) range of compilers. @base-orphans@ does not export anything except the orphan instances themselves and complements @<http://hackage.haskell.org/package/base-compat base-compat>@.                      See the README for what instances are covered: <https://github.com/haskell-compat/base-orphans#readme>. See also the <https://github.com/haskell-compat/base-orphans#what-is-not-covered what is not covered> section.
src/Data/Orphans.hs view
@@ -6,6 +6,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE KindSignatures #-}+{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-}@@ -370,8 +371,8 @@ instance (Storable a, RealFloat a) # endif   => Storable (Complex a) where-    sizeOf (a :+ _)    = 2 * sizeOf a-    alignment (a :+ _) = alignment a+    sizeOf a       = 2 * sizeOf (realPart a)+    alignment a    = alignment (realPart a)     peek p           = do                         q <- return $ castPtr p                         r <- peek q@@ -383,8 +384,8 @@                         pokeElemOff q 1 i  instance (Storable a, Integral a) => Storable (Ratio a) where-    sizeOf (n :% _)    = 2 * sizeOf n-    alignment (n :% _) = alignment n+    sizeOf _    = 2 * sizeOf (undefined :: a)+    alignment _ = alignment (undefined :: a )     peek p           = do                         q <- return $ castPtr p                         r <- peek q@@ -585,14 +586,6 @@ instance Monad Complex where   return a = a :+ a   a :+ b >>= f = realPart (f a) :+ imagPart (f b)---- | Extracts the real part of a complex number.-realPart :: Complex a -> a-realPart (x :+ _) =  x---- | Extracts the imaginary part of a complex number.-imagPart :: Complex a -> a-imagPart (_ :+ y) =  y  instance MonadZip Dual where     -- Cannot use coerce, it's unsafe
src/Data/Orphans/Prelude.hs view
@@ -13,7 +13,7 @@ #if MIN_VERSION_base(4,9,0)     () where #else-    (module OrphansPrelude) where+    (module OrphansPrelude, realPart, imagPart) where  import Control.Applicative as OrphansPrelude import Control.Arrow as OrphansPrelude hiding (loop)@@ -103,5 +103,13 @@ # if MIN_VERSION_base(4,8,0) import Data.Functor.Identity as OrphansPrelude # endif++# if MIN_VERSION_base(4,4,0)+realPart, imagPart :: Complex a -> a+#else+realPart, imagPart :: RealFloat a => Complex a -> a+#endif+realPart (x :+ _) = x+imagPart (_ :+ y) = y  #endif
test/Foreign/Storable/OrphansSpec.hs view
@@ -13,12 +13,12 @@ spec = do   describe "Storable Complex instance" $ do     it "has twice the sizeOf its realPart" $ do-      sizeOf ((1 :: Double) :+ 2) `shouldBe` 2*sizeOf (1 :: Double)+      sizeOf (undefined :: Complex Double) `shouldBe` 2*sizeOf (1 :: Double)     it "has the alignment of its realPart" $ do-      alignment ((1 :: Double) :+ 2) `shouldBe` alignment (1 :: Double)+      alignment (undefined :: Complex Double) `shouldBe` alignment (1 :: Double)    describe "Storable Ratio instance" $ do     it "has twice the sizeOf its parameterized type" $ do-      sizeOf ((1 :: Int) % 2) `shouldBe` 2*sizeOf (1 :: Int)+      sizeOf (undefined :: Ratio Int) `shouldBe` 2*sizeOf (1 :: Int)     it "has the alignment of its parameterized type" $ do-      alignment ((1 :: Int) % 2) `shouldBe` alignment (1 :: Int)+      alignment (undefined :: Ratio Int) `shouldBe` alignment (1 :: Int)