diff options
author | Shane O'Brien <shane@duairc.com> | 2016-04-11 02:53:00 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-04-11 02:53:16 +0200 |
commit | 8b57cac5974c9fffccbcae3104b5b5d18760749e (patch) | |
tree | 8d052b9163fc40d0b54b8d43348d529b116f125c /libraries/base | |
parent | 02a5c580b6078630842f4c3db5d92631fada21e9 (diff) | |
download | haskell-8b57cac5974c9fffccbcae3104b5b5d18760749e.tar.gz |
Added (more) missing instances for Identity and Const
* `Identity` and `Const` now have `Num`, `Real`, `Integral`,
`Fractional`, `Floating`, `RealFrac` and `RealFloat` instances
* `Identity` and `Const` now have `Bits` and `FiniteBits` instances
* `Identity` and `Const` now have `IsString` instances
Reviewers: RyanGlScott, austin, hvr, bgamari, ekmett
Reviewed By: ekmett
Subscribers: nomeata, ekmett, RyanGlScott, thomie
Differential Revision: https://phabricator.haskell.org/D2079
GHC Trac Issues: #11790
Diffstat (limited to 'libraries/base')
-rw-r--r-- | libraries/base/Data/Functor/Const.hs | 11 | ||||
-rw-r--r-- | libraries/base/Data/Functor/Identity.hs | 7 | ||||
-rw-r--r-- | libraries/base/Data/String.hs | 3 | ||||
-rw-r--r-- | libraries/base/changelog.md | 6 |
4 files changed, 19 insertions, 8 deletions
diff --git a/libraries/base/Data/Functor/Const.hs b/libraries/base/Data/Functor/Const.hs index 745795181a..9f2db7f1dc 100644 --- a/libraries/base/Data/Functor/Const.hs +++ b/libraries/base/Data/Functor/Const.hs @@ -1,9 +1,9 @@ -{-# LANGUAGE Trustworthy #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE Trustworthy #-} ----------------------------------------------------------------------------- -- | @@ -21,20 +21,25 @@ module Data.Functor.Const (Const(..)) where +import Data.Bits (Bits, FiniteBits) import Data.Foldable (Foldable(foldMap)) import Foreign.Storable (Storable) import GHC.Arr (Ix) import GHC.Base import GHC.Enum (Bounded, Enum) +import GHC.Float (Floating, RealFloat) import GHC.Generics (Generic, Generic1) +import GHC.Num (Num) +import GHC.Real (Fractional, Integral, Real, RealFrac) import GHC.Read (Read(readsPrec), readParen, lex) import GHC.Show (Show(showsPrec), showParen, showString) -- | The 'Const' functor. newtype Const a b = Const { getConst :: a } - deriving ( Generic, Generic1, Bounded, Enum, Eq, Ix, Ord - , Monoid, Storable) + deriving ( Bits, Bounded, Enum, Eq, FiniteBits, Floating, Fractional + , Generic, Generic1, Integral, Ix, Monoid, Num, Ord, Real + , RealFrac, RealFloat , Storable) -- | This instance would be equivalent to the derived instances of the -- 'Const' newtype if the 'runConst' field were removed diff --git a/libraries/base/Data/Functor/Identity.hs b/libraries/base/Data/Functor/Identity.hs index df424f2137..4e6646a6ea 100644 --- a/libraries/base/Data/Functor/Identity.hs +++ b/libraries/base/Data/Functor/Identity.hs @@ -36,11 +36,13 @@ module Data.Functor.Identity ( import Control.Monad.Fix import Control.Monad.Zip +import Data.Bits (Bits, FiniteBits) import Data.Coerce import Data.Data (Data) import Data.Foldable import Data.Ix (Ix) import Data.Semigroup (Semigroup) +import Data.String (IsString) import Foreign.Storable (Storable) import GHC.Generics (Generic, Generic1) @@ -48,8 +50,9 @@ import GHC.Generics (Generic, Generic1) -- -- @since 4.8.0.0 newtype Identity a = Identity { runIdentity :: a } - deriving ( Bounded, Enum, Eq, Ix, Ord, Data, Monoid, Semigroup - , Storable, Traversable, Generic, Generic1) + deriving ( Bits, Bounded, Data, Enum, Eq, FiniteBits, Floating, Fractional + , Generic, Generic1, Integral, IsString, Ix, Monoid, Num, Ord + , Real, RealFrac, RealFloat , Semigroup, Storable, Traversable) -- | This instance would be equivalent to the derived instances of the -- 'Identity' newtype if the 'runIdentity' field were removed diff --git a/libraries/base/Data/String.hs b/libraries/base/Data/String.hs index 9e1f5f340f..f341ff2415 100644 --- a/libraries/base/Data/String.hs +++ b/libraries/base/Data/String.hs @@ -28,6 +28,7 @@ module Data.String ( ) where import GHC.Base +import Data.Functor.Const (Const (Const)) import Data.List (lines, words, unlines, unwords) -- | Class for string-like datastructures; used by the overloaded string @@ -78,3 +79,5 @@ instance (a ~ Char) => IsString [a] where -- See Note [IsString String] fromString xs = xs +instance IsString a => IsString (Const a b) where + fromString = Const . fromString diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md index cb3eceda98..f935c59bda 100644 --- a/libraries/base/changelog.md +++ b/libraries/base/changelog.md @@ -131,9 +131,9 @@ * `Identity` now has `Semigroup` and `Monoid` instances - * `Identity` and `Const` now have `Bounded`, `Enum` and `Ix` instances - - * `Identity` and `Const` now have `Storable` instances + * `Identity` and `Const` now have `Bits`, `Bounded`, `Enum`, `FiniteBits`, + `Floating`, `Fractional`, `Integral`, `IsString`, `Ix`, `Num`, `Real`, + `RealFloat`, `RealFrac` and `Storable` instances. (#11210, #11790) * `()` now has a `Storable` instance |