[Git][ghc/ghc][wip/VeryMilkyJoe/mv-const-base] Move Identity and Const from internal to base
Jana Chadt pushed to branch wip/VeryMilkyJoe/mv-const-base at Glasgow Haskell Compiler / GHC Commits: f2044a46 by Jana Chadt at 2026-02-25T12:39:35+01:00 Move Identity and Const from internal to base Move identity and respective instances from internal to base. Currently this is not quite possible, since Data in internal uses both, Identity and Const in its typeclass method implementations. Once this has been moved, we can update this commit. Ticket: #26957 - - - - - 9 changed files: - libraries/base/src/Data/Functor/Const.hs - libraries/base/src/Data/Functor/Identity.hs - libraries/base/src/Data/Traversable.hs - libraries/ghc-internal/ghc-internal.cabal.in - libraries/ghc-internal/src/GHC/Internal/Control/Monad/Zip.hs - − libraries/ghc-internal/src/GHC/Internal/Data/Functor/Const.hs - − libraries/ghc-internal/src/GHC/Internal/Data/Functor/Identity.hs - libraries/ghc-internal/src/GHC/Internal/Data/String.hs - libraries/ghc-internal/src/GHC/Internal/Data/Traversable.hs Changes: ===================================== libraries/base/src/Data/Functor/Const.hs ===================================== @@ -1,5 +1,12 @@ +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE PolyKinds #-} {-# LANGUAGE Safe #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE Trustworthy #-} +----------------------------------------------------------------------------- -- | -- -- Module : Data.Functor.Const @@ -9,9 +16,105 @@ -- Maintainer : libraries@haskell.org -- Stability : stable -- Portability : portable +----------------------------------------------------------------------------- + +-- The 'Const' functor. +-- +-- @since base-4.9.0.0 module Data.Functor.Const (Const(..) ) where -import GHC.Internal.Data.Functor.Const \ No newline at end of file +import GHC.Internal.Data.Bits (Bits, FiniteBits) +import GHC.Internal.Data.Foldable (Foldable(foldMap)) +import GHC.Internal.Data.String (IsString) +import GHC.Internal.Foreign.Storable (Storable) + +import GHC.Internal.Ix (Ix) +import GHC.Internal.Base +import GHC.Internal.Enum (Bounded, Enum) +import GHC.Internal.Float (Floating, RealFloat) +import GHC.Internal.Generics (Generic, Generic1) +import GHC.Internal.Num (Num) +import GHC.Internal.Real (Fractional, Integral, Real, RealFrac) +import GHC.Internal.Read (Read(readsPrec), readParen, lex) +import GHC.Internal.Show (Show(showsPrec), showParen, showString) + +-- | The 'Const' functor. +-- +-- ==== __Examples__ +-- +-- >>> fmap (++ "World") (Const "Hello") +-- Const "Hello" +-- +-- Because we ignore the second type parameter to 'Const', +-- the Applicative instance, which has +-- @'(<*>)' :: Monoid m => Const m (a -> b) -> Const m a -> Const m b@ +-- essentially turns into @Monoid m => m -> m -> m@, which is '(<>)' +-- +-- >>> Const [1, 2, 3] <*> Const [4, 5, 6] +-- Const [1,2,3,4,5,6] +newtype Const a b = Const { getConst :: a } + deriving ( Bits -- ^ @since base-4.9.0.0 + , Bounded -- ^ @since base-4.9.0.0 + , Enum -- ^ @since base-4.9.0.0 + , Eq -- ^ @since base-4.9.0.0 + , FiniteBits -- ^ @since base-4.9.0.0 + , Floating -- ^ @since base-4.9.0.0 + , Fractional -- ^ @since base-4.9.0.0 + , Generic -- ^ @since base-4.9.0.0 + , Generic1 -- ^ @since base-4.9.0.0 + , Integral -- ^ @since base-4.9.0.0 + , Ix -- ^ @since base-4.9.0.0 + , Semigroup -- ^ @since base-4.9.0.0 + , Monoid -- ^ @since base-4.9.0.0 + , Num -- ^ @since base-4.9.0.0 + , Ord -- ^ @since base-4.9.0.0 + , Real -- ^ @since base-4.9.0.0 + , RealFrac -- ^ @since base-4.9.0.0 + , RealFloat -- ^ @since base-4.9.0.0 + , Storable -- ^ @since base-4.9.0.0 + ) + +-- | This instance would be equivalent to the derived instances of the +-- 'Const' newtype if the 'getConst' field were removed +-- +-- @since base-4.8.0.0 +instance Read a => Read (Const a b) where + readsPrec d = readParen (d > 10) + $ \r -> [(Const x,t) | ("Const", s) <- lex r, (x, t) <- readsPrec 11 s] + +-- | This instance would be equivalent to the derived instances of the +-- 'Const' newtype if the 'getConst' field were removed +-- +-- @since base-4.8.0.0 +instance Show a => Show (Const a b) where + showsPrec d (Const x) = showParen (d > 10) $ + showString "Const " . showsPrec 11 x + +-- | @since base-4.7.0.0 +instance Foldable (Const m) where + foldMap _ _ = mempty + +-- | @since base-2.01 +instance Functor (Const m) where + fmap _ (Const v) = Const v + +-- | @since base-2.0.1 +instance Monoid m => Applicative (Const m) where + pure _ = Const mempty + liftA2 _ (Const x) (Const y) = Const (x `mappend` y) + (<*>) = coerce (mappend :: m -> m -> m) +-- This is pretty much the same as +-- Const f <*> Const v = Const (f `mappend` v) +-- but guarantees that mappend for Const a b will have the same arity +-- as the one for a; it won't create a closure to raise the arity +-- to 2. + +-- | @since base-4.7.0.0 +instance Traversable (Const m) where + traverse _ (Const m) = pure $ Const m + +-- | @since base-4.9.0.0 +deriving instance IsString a => IsString (Const a (b :: k)) ===================================== libraries/base/src/Data/Functor/Identity.hs ===================================== @@ -29,4 +29,130 @@ module Data.Functor.Identity (Identity(..) ) where -import GHC.Internal.Data.Functor.Identity \ No newline at end of file +import GHC.Internal.Control.Monad.Fix +import GHC.Internal.Data.Bits (Bits, FiniteBits) +import GHC.Internal.Data.Coerce +import GHC.Internal.Data.Foldable +import GHC.Internal.Data.Functor.Utils ((#.)) +import GHC.Internal.Data.String (IsString) +import GHC.Internal.Foreign.Storable (Storable) +import GHC.Internal.Ix (Ix) +import GHC.Internal.Base ( Applicative(..), Eq(..), Functor(..), Monad(..) + , Semigroup, Monoid, Ord(..), ($), (.) ) +import GHC.Internal.Enum (Bounded, Enum) +import GHC.Internal.Float (Floating, RealFloat) +import GHC.Internal.Generics (Generic, Generic1) +import GHC.Internal.Num (Num) +import GHC.Internal.Read (Read(..), lex, readParen) +import GHC.Internal.Real (Fractional, Integral, Real, RealFrac) +import GHC.Internal.Show (Show(..), showParen, showString) +import GHC.Internal.Types (Bool(..)) +import GHC.Internal.Control.Monad.Zip (MonadZip(..)) + +-- | Identity functor and monad. (a non-strict monad) +-- +-- ==== __Examples__ +-- +-- >>> fmap (+1) (Identity 0) +-- Identity 1 +-- +-- >>> Identity [1, 2, 3] <> Identity [4, 5, 6] +-- Identity [1,2,3,4,5,6] +-- +-- @ +-- >>> do +-- x <- Identity 10 +-- y <- Identity (x + 5) +-- pure (x + y) +-- Identity 25 +-- @ +-- +-- @since base-4.8.0.0 +newtype Identity a = Identity { runIdentity :: a } + deriving ( Bits -- ^ @since base-4.9.0.0 + , Bounded -- ^ @since base-4.9.0.0 + , Enum -- ^ @since base-4.9.0.0 + , Eq -- ^ @since base-4.8.0.0 + , FiniteBits -- ^ @since base-4.9.0.0 + , Floating -- ^ @since base-4.9.0.0 + , Fractional -- ^ @since base-4.9.0.0 + , Generic -- ^ @since base-4.8.0.0 + , Generic1 -- ^ @since base-4.8.0.0 + , Integral -- ^ @since base-4.9.0.0 + , Ix -- ^ @since base-4.9.0.0 + , Semigroup -- ^ @since base-4.9.0.0 + , Monoid -- ^ @since base-4.9.0.0 + , Num -- ^ @since base-4.9.0.0 + , Ord -- ^ @since base-4.8.0.0 + , Real -- ^ @since base-4.9.0.0 + , RealFrac -- ^ @since base-4.9.0.0 + , RealFloat -- ^ @since base-4.9.0.0 + , Storable -- ^ @since base-4.9.0.0 + ) + +-- | This instance would be equivalent to the derived instances of the +-- 'Identity' newtype if the 'runIdentity' field were removed +-- +-- @since base-4.8.0.0 +instance (Read a) => Read (Identity a) where + readsPrec d = readParen (d > 10) $ \ r -> + [(Identity x,t) | ("Identity",s) <- lex r, (x,t) <- readsPrec 11 s] + +-- | This instance would be equivalent to the derived instances of the +-- 'Identity' newtype if the 'runIdentity' field were removed +-- +-- @since base-4.8.0.0 +instance (Show a) => Show (Identity a) where + showsPrec d (Identity x) = showParen (d > 10) $ + showString "Identity " . showsPrec 11 x + +-- --------------------------------------------------------------------------- +-- Identity instances for Functor and Monad + +-- | @since base-4.8.0.0 +instance Foldable Identity where + foldMap = coerce + + elem = (. runIdentity) #. (==) + foldl = coerce + foldl' = coerce + foldl1 _ = runIdentity + foldr f z (Identity x) = f x z + foldr' = foldr + foldr1 _ = runIdentity + length _ = 1 + maximum = runIdentity + minimum = runIdentity + null _ = False + product = runIdentity + sum = runIdentity + toList (Identity x) = [x] + +-- | @since base-4.8.0.0 +instance Functor Identity where + fmap = coerce + +-- | @since base-4.8.0.0 +instance Applicative Identity where + pure = Identity + (<*>) = coerce + liftA2 = coerce + +-- | @since base-4.8.0.0 +instance Monad Identity where + m >>= k = k (runIdentity m) + +-- | @since base-4.8.0.0 +instance MonadFix Identity where + mfix f = Identity (fix (runIdentity . f)) + +-- | @since 4.8.0.0 +instance MonadZip Identity where + mzipWith = liftM2 + munzip (Identity (a, b)) = (Identity a, Identity b) + +-- | @since base-4.9.0.0 +deriving instance Traversable Identity + +-- | @since base-4.9.0.0 +deriving instance IsString a => IsString (Identity a) ===================================== libraries/base/src/Data/Traversable.hs ===================================== @@ -86,6 +86,32 @@ module Data.Traversable ( import GHC.Internal.Data.Traversable +-- | This function may be used as a value for `fmap` in a `Functor` +-- instance, provided that 'traverse' is defined. (Using +-- `fmapDefault` with a `Traversable` instance defined only by +-- 'sequenceA' will result in infinite recursion.) +-- +-- @ +-- 'fmapDefault' f ≡ 'runIdentity' . 'traverse' ('Identity' . f) +-- @ +fmapDefault :: forall t a b . Traversable t + => (a -> b) -> t a -> t b +{-# INLINE fmapDefault #-} +-- See Note [Function coercion] in Data.Functor.Utils. +fmapDefault = coerce (traverse @t @Identity @a @b) + +-- | This function may be used as a value for `Data.Foldable.foldMap` +-- in a `Foldable` instance. +-- +-- @ +-- 'foldMapDefault' f ≡ 'getConst' . 'traverse' ('Const' . f) +-- @ +foldMapDefault :: forall t m a . (Traversable t, Monoid m) + => (a -> m) -> t a -> m +{-# INLINE foldMapDefault #-} +-- See Note [Function coercion] in Data.Functor.Utils. +foldMapDefault = coerce (traverse @t @(Const m) @a @()) + -- $setup -- >>> import Prelude -- >>> import Data.Maybe ===================================== libraries/ghc-internal/ghc-internal.cabal.in ===================================== @@ -148,8 +148,6 @@ Library GHC.Internal.Data.Foldable GHC.Internal.Data.Function GHC.Internal.Data.Functor - GHC.Internal.Data.Functor.Const - GHC.Internal.Data.Functor.Identity GHC.Internal.Data.Functor.Utils GHC.Internal.Data.IORef GHC.Internal.Data.List ===================================== libraries/ghc-internal/src/GHC/Internal/Control/Monad/Zip.hs ===================================== @@ -19,7 +19,6 @@ module GHC.Internal.Control.Monad.Zip ( MonadZip(..) ) where import GHC.Internal.Control.Monad (liftM, liftM2, Monad(..)) -import GHC.Internal.Data.Functor.Identity import qualified GHC.Internal.Data.Functor import GHC.Internal.Data.Monoid import GHC.Internal.Data.NonEmpty ( NonEmpty(..) ) @@ -73,11 +72,6 @@ instance MonadZip NonEmpty where mzipWith = NE.zipWith munzip = GHC.Internal.Data.Functor.unzip --- | @since 4.8.0.0 -instance MonadZip Identity where - mzipWith = liftM2 - munzip (Identity (a, b)) = (Identity a, Identity b) - -- | @since 4.15.0.0 instance MonadZip Solo where mzipWith = liftM2 ===================================== libraries/ghc-internal/src/GHC/Internal/Data/Functor/Const.hs deleted ===================================== @@ -1,107 +0,0 @@ -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE NoImplicitPrelude #-} -{-# LANGUAGE PolyKinds #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE Trustworthy #-} - ------------------------------------------------------------------------------ --- | --- Module : GHC.Internal.Data.Functor.Const --- Copyright : Conor McBride and Ross Paterson 2005 --- License : BSD-style (see the LICENSE file in the distribution) --- --- Maintainer : libraries@haskell.org --- Stability : stable --- Portability : portable - --- The 'Const' functor. --- --- @since base-4.9.0.0 - -module GHC.Internal.Data.Functor.Const (Const(..)) where - -import GHC.Internal.Data.Bits (Bits, FiniteBits) -import GHC.Internal.Data.Foldable (Foldable(foldMap)) -import GHC.Internal.Foreign.Storable (Storable) - -import GHC.Internal.Ix (Ix) -import GHC.Internal.Base -import GHC.Internal.Enum (Bounded, Enum) -import GHC.Internal.Float (Floating, RealFloat) -import GHC.Internal.Generics (Generic, Generic1) -import GHC.Internal.Num (Num) -import GHC.Internal.Real (Fractional, Integral, Real, RealFrac) -import GHC.Internal.Read (Read(readsPrec), readParen, lex) -import GHC.Internal.Show (Show(showsPrec), showParen, showString) - --- | The 'Const' functor. --- --- ==== __Examples__ --- --- >>> fmap (++ "World") (Const "Hello") --- Const "Hello" --- --- Because we ignore the second type parameter to 'Const', --- the Applicative instance, which has --- @'(<*>)' :: Monoid m => Const m (a -> b) -> Const m a -> Const m b@ --- essentially turns into @Monoid m => m -> m -> m@, which is '(<>)' --- --- >>> Const [1, 2, 3] <*> Const [4, 5, 6] --- Const [1,2,3,4,5,6] -newtype Const a b = Const { getConst :: a } - deriving ( Bits -- ^ @since base-4.9.0.0 - , Bounded -- ^ @since base-4.9.0.0 - , Enum -- ^ @since base-4.9.0.0 - , Eq -- ^ @since base-4.9.0.0 - , FiniteBits -- ^ @since base-4.9.0.0 - , Floating -- ^ @since base-4.9.0.0 - , Fractional -- ^ @since base-4.9.0.0 - , Generic -- ^ @since base-4.9.0.0 - , Generic1 -- ^ @since base-4.9.0.0 - , Integral -- ^ @since base-4.9.0.0 - , Ix -- ^ @since base-4.9.0.0 - , Semigroup -- ^ @since base-4.9.0.0 - , Monoid -- ^ @since base-4.9.0.0 - , Num -- ^ @since base-4.9.0.0 - , Ord -- ^ @since base-4.9.0.0 - , Real -- ^ @since base-4.9.0.0 - , RealFrac -- ^ @since base-4.9.0.0 - , RealFloat -- ^ @since base-4.9.0.0 - , Storable -- ^ @since base-4.9.0.0 - ) - --- | This instance would be equivalent to the derived instances of the --- 'Const' newtype if the 'getConst' field were removed --- --- @since base-4.8.0.0 -instance Read a => Read (Const a b) where - readsPrec d = readParen (d > 10) - $ \r -> [(Const x,t) | ("Const", s) <- lex r, (x, t) <- readsPrec 11 s] - --- | This instance would be equivalent to the derived instances of the --- 'Const' newtype if the 'getConst' field were removed --- --- @since base-4.8.0.0 -instance Show a => Show (Const a b) where - showsPrec d (Const x) = showParen (d > 10) $ - showString "Const " . showsPrec 11 x - --- | @since base-4.7.0.0 -instance Foldable (Const m) where - foldMap _ _ = mempty - --- | @since base-2.01 -instance Functor (Const m) where - fmap _ (Const v) = Const v - --- | @since base-2.0.1 -instance Monoid m => Applicative (Const m) where - pure _ = Const mempty - liftA2 _ (Const x) (Const y) = Const (x `mappend` y) - (<*>) = coerce (mappend :: m -> m -> m) --- This is pretty much the same as --- Const f <*> Const v = Const (f `mappend` v) --- but guarantees that mappend for Const a b will have the same arity --- as the one for a; it won't create a closure to raise the arity --- to 2. ===================================== libraries/ghc-internal/src/GHC/Internal/Data/Functor/Identity.hs deleted ===================================== @@ -1,149 +0,0 @@ -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE NoImplicitPrelude #-} -{-# LANGUAGE Trustworthy #-} - ------------------------------------------------------------------------------ --- | --- Module : GHC.Internal.Data.Functor.Identity --- Copyright : (c) Andy Gill 2001, --- (c) Oregon Graduate Institute of Science and Technology 2001 --- License : BSD-style (see the file LICENSE) --- --- Maintainer : ross@soi.city.ac.uk --- Stability : stable --- Portability : portable --- --- The identity functor and monad. --- --- This trivial type constructor serves two purposes: --- --- * It can be used with functions parameterized by functor or monad classes. --- --- * It can be used as a base monad to which a series of monad --- transformers may be applied to construct a composite monad. --- Most monad transformer modules include the special case of --- applying the transformer to 'Identity'. For example, @State s@ --- is an abbreviation for @StateT s 'Identity'@. --- --- @since base-4.8.0.0 ------------------------------------------------------------------------------ - -module GHC.Internal.Data.Functor.Identity ( - Identity(..), - ) where - -import GHC.Internal.Control.Monad.Fix -import GHC.Internal.Data.Bits (Bits, FiniteBits) -import GHC.Internal.Data.Coerce -import GHC.Internal.Data.Foldable -import GHC.Internal.Data.Functor.Utils ((#.)) -import GHC.Internal.Foreign.Storable (Storable) -import GHC.Internal.Ix (Ix) -import GHC.Internal.Base ( Applicative(..), Eq(..), Functor(..), Monad(..) - , Semigroup, Monoid, Ord(..), ($), (.) ) -import GHC.Internal.Enum (Bounded, Enum) -import GHC.Internal.Float (Floating, RealFloat) -import GHC.Internal.Generics (Generic, Generic1) -import GHC.Internal.Num (Num) -import GHC.Internal.Read (Read(..), lex, readParen) -import GHC.Internal.Real (Fractional, Integral, Real, RealFrac) -import GHC.Internal.Show (Show(..), showParen, showString) -import GHC.Internal.Types (Bool(..)) - --- | Identity functor and monad. (a non-strict monad) --- --- ==== __Examples__ --- --- >>> fmap (+1) (Identity 0) --- Identity 1 --- --- >>> Identity [1, 2, 3] <> Identity [4, 5, 6] --- Identity [1,2,3,4,5,6] --- --- @ --- >>> do --- x <- Identity 10 --- y <- Identity (x + 5) --- pure (x + y) --- Identity 25 --- @ --- --- @since base-4.8.0.0 -newtype Identity a = Identity { runIdentity :: a } - deriving ( Bits -- ^ @since base-4.9.0.0 - , Bounded -- ^ @since base-4.9.0.0 - , Enum -- ^ @since base-4.9.0.0 - , Eq -- ^ @since base-4.8.0.0 - , FiniteBits -- ^ @since base-4.9.0.0 - , Floating -- ^ @since base-4.9.0.0 - , Fractional -- ^ @since base-4.9.0.0 - , Generic -- ^ @since base-4.8.0.0 - , Generic1 -- ^ @since base-4.8.0.0 - , Integral -- ^ @since base-4.9.0.0 - , Ix -- ^ @since base-4.9.0.0 - , Semigroup -- ^ @since base-4.9.0.0 - , Monoid -- ^ @since base-4.9.0.0 - , Num -- ^ @since base-4.9.0.0 - , Ord -- ^ @since base-4.8.0.0 - , Real -- ^ @since base-4.9.0.0 - , RealFrac -- ^ @since base-4.9.0.0 - , RealFloat -- ^ @since base-4.9.0.0 - , Storable -- ^ @since base-4.9.0.0 - ) - --- | This instance would be equivalent to the derived instances of the --- 'Identity' newtype if the 'runIdentity' field were removed --- --- @since base-4.8.0.0 -instance (Read a) => Read (Identity a) where - readsPrec d = readParen (d > 10) $ \ r -> - [(Identity x,t) | ("Identity",s) <- lex r, (x,t) <- readsPrec 11 s] - --- | This instance would be equivalent to the derived instances of the --- 'Identity' newtype if the 'runIdentity' field were removed --- --- @since base-4.8.0.0 -instance (Show a) => Show (Identity a) where - showsPrec d (Identity x) = showParen (d > 10) $ - showString "Identity " . showsPrec 11 x - --- --------------------------------------------------------------------------- --- Identity instances for Functor and Monad - --- | @since base-4.8.0.0 -instance Foldable Identity where - foldMap = coerce - - elem = (. runIdentity) #. (==) - foldl = coerce - foldl' = coerce - foldl1 _ = runIdentity - foldr f z (Identity x) = f x z - foldr' = foldr - foldr1 _ = runIdentity - length _ = 1 - maximum = runIdentity - minimum = runIdentity - null _ = False - product = runIdentity - sum = runIdentity - toList (Identity x) = [x] - --- | @since base-4.8.0.0 -instance Functor Identity where - fmap = coerce - --- | @since base-4.8.0.0 -instance Applicative Identity where - pure = Identity - (<*>) = coerce - liftA2 = coerce - --- | @since base-4.8.0.0 -instance Monad Identity where - m >>= k = k (runIdentity m) - --- | @since base-4.8.0.0 -instance MonadFix Identity where - mfix f = Identity (fix (runIdentity . f)) ===================================== libraries/ghc-internal/src/GHC/Internal/Data/String.hs ===================================== @@ -33,8 +33,6 @@ module GHC.Internal.Data.String ( ) where import GHC.Internal.Base -import GHC.Internal.Data.Functor.Const (Const (Const)) -import GHC.Internal.Data.Functor.Identity (Identity (Identity)) import GHC.Internal.Data.List (lines, words, unlines, unwords) -- | `IsString` is used in combination with the @-XOverloadedStrings@ @@ -105,9 +103,3 @@ ensure the good behavior of the above example remains in the future. instance (a ~ Char) => IsString [a] where -- See Note [IsString String] fromString xs = xs - --- | @since base-4.9.0.0 -deriving instance IsString a => IsString (Const a (b :: k)) - --- | @since base-4.9.0.0 -deriving instance IsString a => IsString (Identity a) ===================================== libraries/ghc-internal/src/GHC/Internal/Data/Traversable.hs ===================================== @@ -32,17 +32,12 @@ module GHC.Internal.Data.Traversable ( mapAccumL, mapAccumR, mapAccumM, - -- * General definitions for superclass methods - fmapDefault, - foldMapDefault, ) where import GHC.Internal.Data.Coerce import GHC.Internal.Data.Either ( Either(..) ) import GHC.Internal.Data.Foldable import GHC.Internal.Data.Functor -import GHC.Internal.Data.Functor.Const ( Const(..) ) -import GHC.Internal.Data.Functor.Identity ( Identity(..) ) import GHC.Internal.Data.Functor.Utils ( StateL(..), StateR(..), StateT(..), (#.) ) import GHC.Internal.Data.Monoid ( Dual(..), Sum(..), Product(..), First(..), Last(..), Alt(..), Ap(..) ) @@ -274,10 +269,6 @@ instance Traversable Proxy where sequence _ = pure Proxy {-# INLINE sequence #-} --- | @since base-4.7.0.0 -instance Traversable (Const m) where - traverse _ (Const m) = pure $ Const m - -- | @since base-4.8.0.0 instance Traversable Dual where traverse f (Dual x) = Dual <$> f x @@ -306,10 +297,6 @@ instance (Traversable f) => Traversable (Alt f) where instance (Traversable f) => Traversable (Ap f) where traverse f (Ap x) = Ap <$> traverse f x --- | @since base-4.9.0.0 -deriving instance Traversable Identity - - -- Instances for GHC.Generics -- | @since base-4.9.0.0 instance Traversable U1 where @@ -460,29 +447,3 @@ forAccumM => s -> t a -> (s -> a -> m (s, b)) -> m (s, t b) {-# INLINE forAccumM #-} forAccumM s t f = mapAccumM f s t - --- | This function may be used as a value for `fmap` in a `Functor` --- instance, provided that 'traverse' is defined. (Using --- `fmapDefault` with a `Traversable` instance defined only by --- 'sequenceA' will result in infinite recursion.) --- --- @ --- 'fmapDefault' f ≡ 'runIdentity' . 'traverse' ('Identity' . f) --- @ -fmapDefault :: forall t a b . Traversable t - => (a -> b) -> t a -> t b -{-# INLINE fmapDefault #-} --- See Note [Function coercion] in Data.Functor.Utils. -fmapDefault = coerce (traverse @t @Identity @a @b) - --- | This function may be used as a value for `Data.Foldable.foldMap` --- in a `Foldable` instance. --- --- @ --- 'foldMapDefault' f ≡ 'getConst' . 'traverse' ('Const' . f) --- @ -foldMapDefault :: forall t m a . (Traversable t, Monoid m) - => (a -> m) -> t a -> m -{-# INLINE foldMapDefault #-} --- See Note [Function coercion] in Data.Functor.Utils. -foldMapDefault = coerce (traverse @t @(Const m) @a @()) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f2044a46fb54a762431c8ccce057f2d8... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f2044a46fb54a762431c8ccce057f2d8... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Jana Chadt (@VeryMilkyJoe)