base-orphans 0.1.0 → 0.2.0
raw patch · 4 files changed
+170/−41 lines, 4 filesdep ~basedep ~hspecPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, hspec
API changes (from Hackage documentation)
+ Data.Orphans: instance Typeable AnnotationWrapper
+ Data.Orphans: instance Typeable BufferList
+ Data.Orphans: instance Typeable ForeignPtrContents
+ Data.Orphans: instance Typeable GHCiSandboxIO
+ Data.Orphans: instance Typeable HandleType
+ Data.Orphans: instance Typeable KProxy
+ Data.Orphans: instance Typeable NoIO
+ Data.Orphans: instance Typeable STret
Files
- CHANGES.markdown +12/−1
- README.markdown +8/−4
- base-orphans.cabal +12/−9
- src/Data/Orphans.hs +138/−27
CHANGES.markdown view
@@ -1,1 +1,12 @@-+## Changes in next+ - Drop GHC 6.12 (and `base-4.2.0.0`) compatibility+ - Fix Windows, GHCJS build+ - `Read` instance for `Fixed`+ - `Applicative` instances for strict and lazy `ST`+ - `Typeable` instance for `SampleVar`+ - `Applicative` and `Alternative` instances for `ReadP` and `ReadPrec`+ - `Typeable` instance for `KProxy`+ - `Typeable` instances for more data types in `GHC.`-prefixed modules+ - `Generic` instances for `Arity`, `Associativity`, and `Fixity` from+ the `GHC.Generics` module+ - Corrected the `Generic` instance for `(:*:)` to work around GHC bug #9830
README.markdown view
@@ -2,7 +2,10 @@ ## Scope -`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, making it a leaner dependency than `base-compat`.+`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+[base-compat](http://hackage.haskell.org/package/base-compat). ## Usage @@ -10,6 +13,7 @@ ## What is covered + * Added `Applicative` and `Alternative` instances for `ReadP` and `ReadPrec` * Added `Eq` and `Ord` instances for `Control.Exception.ErrorCall` * Added `Eq`, `Ord`, `Read`, and `Show` instances for data types in `GHC.Generics` * Added `Monoid`, `Eq`, `Ord`, `Read`, and `Show` instances for `Const`@@ -17,12 +21,15 @@ * Added `Eq`, `Ord`, `Read`, and `Show` instances for `ZipList` * Added `Monad` instance for `WrappedMonad` * Added `Data` and `IsList` instances for `Version`+ * `Applicative` instance for strict and lazy `ST` * `Bits` instance for `Bool`+ * `Generic` instances for the data types in `GHC.Generics` * `Generic` instance for `All`, `Any`, `Const`, `Dual`, `Endo`, `First`, `Last`, `Product`, `Sum`, `WrappedArrow`, `WrappedMonad`, and `ZipList` * `Generic1` instance for `Const`, `Dual`, `First`, `Last`, `Product`, `Sum`, `WrappedArrow`, `WrappedMonad`, and `ZipList` * `Foldable` instance for `Either`, `(,)` and `Const` * `Functor` instance for `ArgOrder`, `OptDescr`, and `ArgDescr` * `Num` instance for `Sum` and `Product`+ * `Read` instance for `Fixed` * `Storable` instance for `Complex` and `Ratio` * `Traversable` instance for `Either`, `(,)` and `Const` * `Typeable` instance for most data types and typeclasses (when possible)@@ -45,8 +52,5 @@ * `ghc-7.0.3` / `base-4.3.1.0` * `ghc-7.0.2` / `base-4.3.1.0` * `ghc-7.0.1` / `base-4.3.0.0`- * `ghc-6.12.3` / `base-4.2.0.2`- * `ghc-6.12.2` / `base-4.2.0.1`- * `ghc-6.12.1` / `base-4.2.0.0` Patches are welcome; add tests for new code!
base-orphans.cabal view
@@ -1,5 +1,5 @@ name: base-orphans-version: 0.1.0+version: 0.2.0 synopsis: Backwards-compatible orphan instances for base homepage: https://github.com/haskell-compat/base-orphans license: MIT@@ -15,13 +15,14 @@ (c) 2015 Ryan Scott category: Compatibility build-type: Simple-cabal-version: >=1.8+cabal-version: >= 1.10 extra-source-files: CHANGES.markdown, README.markdown 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, making it a leaner dependency- than @<http://hackage.haskell.org/package/base-compat base-compat>@.+ 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>@@ -34,12 +35,13 @@ ghc-options: -Wall build-depends:- base == 4.*+ base >= 4.3 && < 5 , ghc-prim hs-source-dirs: src exposed-modules: Data.Orphans+ default-language: Haskell2010 test-suite spec type:@@ -51,6 +53,7 @@ main-is: Spec.hs build-depends:- base > 4.0+ base >= 4.3 && < 5 , base-orphans- , hspec >= 1.8+ , hspec == 2.*+ default-language: Haskell2010
src/Data/Orphans.hs view
@@ -1,13 +1,17 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} -#if __GLASGOW_HASKELL__ >= 706+#if __GLASGOW_HASKELL__ >= 704 {-# LANGUAGE DeriveGeneric #-}+#endif++#if __GLASGOW_HASKELL__ >= 706 {-# LANGUAGE PolyKinds #-} #endif @@ -19,14 +23,23 @@ -} module Data.Orphans () where -#if MIN_VERSION_base(4,2,0) && !(MIN_VERSION_base(4,3,0))-import Data.Unique-# endif+#if !(MIN_VERSION_base(4,4,0))+import Control.Concurrent.SampleVar+import Control.Monad.ST as Strict+import Data.List+#endif +#if !(MIN_VERSION_base(4,4,0)) || (__GLASGOW_HASKELL__ >= 708 && __GLASGOW_HASKELL__ < 710)+import Data.Fixed+#endif+ #if MIN_VERSION_base(4,4,0) && __GLASGOW_HASKELL__ < 710-import GHC.Event import GHC.Fingerprint import GHC.IO.Encoding.Failure++# if !defined(mingw32_HOST_OS) && !defined(__GHCJS__)+import GHC.Event+# endif #endif #if __GLASGOW_HASKELL__ >= 702 && __GLASGOW_HASKELL__ < 710@@ -41,11 +54,18 @@ #if MIN_VERSION_base(4,6,0) && __GLASGOW_HASKELL__ < 710 import Data.Bits import Data.Ord+import GHC.ForeignPtr+import GHC.GHCi import GHC.TypeLits #endif +#if !(MIN_VERSION_base(4,6,0))+import Control.Monad (ap, mplus, mzero)+#endif+ #if MIN_VERSION_base(4,7,0) && __GLASGOW_HASKELL__ < 710 import Control.Concurrent.QSem+import Data.Proxy import Text.Read.Lex (Number) # endif @@ -55,12 +75,12 @@ import Control.Monad import Control.Monad.Fix import Control.Monad.Zip-import Data.Fixed import Data.Ix import Data.Type.Coercion import Data.Type.Equality import GHC.Exts import GHC.IO.BufferedIO+import GHC.IO.Device (IODevice, RawIO) import GHC.IP import Text.Printf #endif@@ -75,7 +95,7 @@ #if __GLASGOW_HASKELL__ < 710 import Control.Applicative import Control.Exception-import Control.Monad.ST.Lazy+import Control.Monad.ST.Lazy as Lazy import Data.Char import Data.Data as Data import Data.Foldable@@ -86,19 +106,60 @@ import Foreign.Marshal.Pool import Foreign.Storable import GHC.Conc+import GHC.Desugar import GHC.IO.Buffer-import GHC.IO.Device+import GHC.IO.Device (IODeviceType) import GHC.IO.Encoding+import GHC.IO.Handle.Types (BufferList, HandleType)+import GHC.ST import System.Console.GetOpt import System.IO import System.IO.Error import Text.ParserCombinators.ReadP import Text.ParserCombinators.ReadPrec as ReadPrec import Text.Read++# if defined(mingw32_HOST_OS)+import GHC.IO.Encoding.CodePage.Table+# endif #endif ------------------------------------------------------------------------------- +#if !(MIN_VERSION_base(4,4,0))+instance HasResolution a => Read (Fixed a) where+ readsPrec _ = readsFixed++readsFixed :: (HasResolution a) => ReadS (Fixed a)+readsFixed = readsSigned+ where readsSigned ('-' : xs) = [ (negate x, rest)+ | (x, rest) <- readsUnsigned xs ]+ readsSigned xs = readsUnsigned xs+ readsUnsigned xs = case span isDigit xs of+ ([], _) -> []+ (is, xs') ->+ let i = fromInteger (read is)+ in case xs' of+ '.' : xs'' ->+ case span isDigit xs'' of+ ([], _) -> []+ (js, xs''') ->+ let j = fromInteger (read js)+ l = genericLength js :: Integer+ in [(i + (j / (10 ^ l)), xs''')]+ _ -> [(i, xs')]++deriving instance Typeable1 SampleVar++instance Applicative (Strict.ST s) where+ pure = return+ (<*>) = ap++instance Applicative (Lazy.ST s) where+ pure = return+ (<*>) = ap+#endif+ -- These instances are only valid if Bits isn't a subclass of Num (as Bool is -- not a Num instance), which is only true as of base-4.6.0.0 and later. #if MIN_VERSION_base(4,6,0) && !(MIN_VERSION_base(4,7,0))@@ -133,6 +194,24 @@ deriving instance Show a => Show (Down a) #endif +#if !(MIN_VERSION_base(4,6,0))+instance Applicative ReadP where+ pure = return+ (<*>) = ap++instance Alternative ReadP where+ empty = mzero+ (<|>) = mplus++instance Applicative ReadPrec where+ pure = return+ (<*>) = ap++instance Alternative ReadPrec where+ empty = mzero+ (<|>) = mplus+#endif+ #if !(MIN_VERSION_base(4,7,0)) instance Foldable ((,) a) where foldMap f (_, y) = f y@@ -179,27 +258,26 @@ deriving instance Read a => Read (ZipList a) deriving instance Show a => Show (ZipList a) -instance Functor ArgOrder where- fmap _ RequireOrder = RequireOrder- fmap _ Permute = Permute- fmap f (ReturnInOrder g) = ReturnInOrder (f . g)--instance Functor OptDescr where- fmap f (Option a b argDescr c) = Option a b (fmap f argDescr) c--instance Functor ArgDescr where- fmap f (NoArg a) = NoArg (f a)- fmap f (ReqArg g s) = ReqArg (f . g) s- fmap f (OptArg g s) = OptArg (f . g) s+deriving instance Functor ArgOrder+deriving instance Functor OptDescr+deriving instance Functor ArgDescr #endif #if __GLASGOW_HASKELL__ >= 702 && !(MIN_VERSION_base(4,7,0)) -- Although DeriveGeneric has been around since GHC 7.2, various bugs cause -- the standalone-derived code below to fail to compile unless a fairly -- recent version of GHC is used.-# if __GLASGOW_HASKELL__ >= 706+# if __GLASGOW_HASKELL__ >= 704 deriving instance Generic All deriving instance Generic Any+deriving instance Generic Arity+deriving instance Generic Associativity+deriving instance Generic Generics.Fixity++deriving instance Generic (U1 p)+# endif++# if __GLASGOW_HASKELL__ >= 706 deriving instance Generic (Const a b) deriving instance Generic (Dual a) deriving instance Generic (Endo a)@@ -221,14 +299,34 @@ deriving instance Generic1 (WrappedMonad m) deriving instance Generic1 ZipList -deriving instance Generic (U1 p) deriving instance Generic (Par1 p) deriving instance Generic (Rec1 f p) deriving instance Generic (K1 i c p) deriving instance Generic (M1 i c f p) deriving instance Generic ((f :+: g) p)-deriving instance Generic ((f :*: g) p) deriving instance Generic ((f :.: g) p)++-- Due to a GHC bug (https://ghc.haskell.org/trac/ghc/ticket/9830), the derived+-- Generic instances for infix data constructors will use the wrong+-- precedence (prior to GHC 7.10).+-- We'll manually derive a Generic :*: instance to avoid this.+instance Generic ((f :*: g) p) where+ type Rep ((f :*: g) p) =+ D1 D_Product (C1 C_Product (S1 NoSelector (Rec0 (f p))+ :*: S1 NoSelector (Rec0 (g p))))+ from (f :*: g) = M1 (M1 (M1 (K1 f) :*: M1 (K1 g)))+ to (M1 (M1 (M1 (K1 f) :*: M1 (K1 g)))) = f :*: g++data D_Product+data C_Product++instance Datatype D_Product where+ datatypeName _ = ":*:"+ moduleName _ = "GHC.Generics"++instance Constructor C_Product where+ conName _ = ":*:"+ conFixity _ = Generics.Infix RightAssociative 6 # endif deriving instance Eq (U1 p)@@ -345,12 +443,14 @@ #if __GLASGOW_HASKELL__ < 710 deriving instance Typeable All+deriving instance Typeable AnnotationWrapper deriving instance Typeable1 ArgDescr deriving instance Typeable1 ArgOrder deriving instance Typeable Monoid.Any deriving instance Typeable BlockReason deriving instance Typeable1 Buffer deriving instance Typeable3 BufferCodec+deriving instance Typeable1 BufferList deriving instance Typeable BufferMode deriving instance Typeable BufferState deriving instance Typeable CFile@@ -369,6 +469,7 @@ deriving instance Typeable GeneralCategory deriving instance Typeable HandlePosn deriving instance Typeable1 Handler+deriving instance Typeable HandleType deriving instance Typeable IODeviceType deriving instance Typeable IOErrorType deriving instance Typeable IOMode@@ -382,14 +483,17 @@ deriving instance Typeable1 ReadP deriving instance Typeable1 ReadPrec deriving instance Typeable SeekMode-deriving instance Typeable2 ST+deriving instance Typeable2 Lazy.ST+deriving instance Typeable2 STret deriving instance Typeable1 Sum deriving instance Typeable TextEncoding deriving instance Typeable ThreadStatus deriving instance Typeable1 ZipList -#if MIN_VERSION_base(4,2,0) && !(MIN_VERSION_base(4,3,0))-deriving instance Typeable Unique+# if defined(mingw32_HOST_OS)+deriving instance Typeable CodePageArrays+deriving instance Typeable2 CompactArray+deriving instance Typeable1 ConvArray # endif # if MIN_VERSION_base(4,3,0)@@ -399,11 +503,14 @@ # if MIN_VERSION_base(4,4,0) deriving instance Typeable CodingFailureMode deriving instance Typeable CodingProgress+deriving instance Typeable Fingerprint++# if !defined(mingw32_HOST_OS) && !defined(__GHCJS__) deriving instance Typeable Event deriving instance Typeable EventManager deriving instance Typeable FdKey-deriving instance Typeable Fingerprint deriving instance Typeable TimeoutKey+# endif # endif # if __GLASGOW_HASKELL__ >= 702@@ -430,7 +537,9 @@ # if MIN_VERSION_base(4,6,0) deriving instance Typeable1 Down+deriving instance Typeable ForeignPtrContents deriving instance Typeable Nat+deriving instance Typeable1 NoIO deriving instance Typeable Symbol # endif @@ -439,6 +548,7 @@ deriving instance Typeable FormatAdjustment deriving instance Typeable FormatParse deriving instance Typeable FormatSign+deriving instance Typeable KProxy deriving instance Typeable Number deriving instance Typeable SomeNat deriving instance Typeable SomeSymbol@@ -539,6 +649,7 @@ deriving instance Typeable Functor deriving instance Typeable Generic deriving instance Typeable Generic1+deriving instance Typeable GHCiSandboxIO deriving instance Typeable HasResolution deriving instance Typeable HPrintfType deriving instance Typeable Integral