Commit 8b57cac5 authored by duairc's avatar duairc Committed by Ben Gamari
Browse files

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
parent 02a5c580
{-# 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
......
......@@ -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
......
......@@ -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
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment