
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: ca5b0283 by Sergey Vinokurov at 2025-09-01T23:02:23-04:00 Remove unnecessary irrefutable patterns from Bifunctor instances for tuples Implementation of https://github.com/haskell/core-libraries-committee/issues/339 Metric Decrease: mhu-perf - - - - - 2 changed files: - libraries/base/changelog.md - libraries/base/src/Data/Bifunctor.hs Changes: ===================================== libraries/base/changelog.md ===================================== @@ -7,6 +7,7 @@ * Modify the implementation of `Data.List.sortOn` to use `(>)` instead of `compare`. ([CLC proposal #332](https://github.com/haskell/core-libraries-committee/issues/332)) * `GHC.Exts.IOPort#` and its related operations have been removed ([CLC #213](https://github.com/haskell/core-libraries-committee/issues/213)) * Fix bug where `naturalAndNot` was incorrectly truncating results ([CLC proposal #350](github.com/haskell/core-libraries-committee/issues/350)) + * Remove extra laziness from `Data.Bifunctor.Bifunctor` instances for all tuples to have the same laziness as their `Data.Functor.Functor` counterparts (i.e. they became more strict than before) ([CLC proposal #339](https://github.com/haskell/core-libraries-committee/issues/339)) ## 4.22.0.0 *TBA* * Shipped with GHC 9.14.1 ===================================== libraries/base/src/Data/Bifunctor.hs ===================================== @@ -133,39 +133,39 @@ class (forall a. Functor (p a)) => Bifunctor p where second = bimap id --- | Class laws for tuples hold only up to laziness. Both --- 'first' 'id' and 'second' 'id' are lazier than 'id' (and 'fmap' 'id'): +-- | Tuple instances have the same laziness as for 'Functor'. Both +-- 'first' 'id' and 'second' 'id' have the same laziness as 'id' (and 'fmap' 'id'): -- --- >>> first id (undefined :: (Int, Word)) `seq` () --- () --- >>> second id (undefined :: (Int, Word)) `seq` () --- () +-- >>> first id (errorWithoutStackTrace "error!" :: (Int, Word)) `seq` () +-- *** Exception: error! +-- >>> second id (errorWithoutStackTrace "error!" :: (Int, Word)) `seq` () +-- *** Exception: error! -- >>> id (errorWithoutStackTrace "error!" :: (Int, Word)) `seq` () -- *** Exception: error! -- -- @since 4.8.0.0 instance Bifunctor (,) where - bimap f g ~(a, b) = (f a, g b) + bimap f g (a, b) = (f a, g b) -- | @since 4.8.0.0 instance Bifunctor ((,,) x1) where - bimap f g ~(x1, a, b) = (x1, f a, g b) + bimap f g (x1, a, b) = (x1, f a, g b) -- | @since 4.8.0.0 instance Bifunctor ((,,,) x1 x2) where - bimap f g ~(x1, x2, a, b) = (x1, x2, f a, g b) + bimap f g (x1, x2, a, b) = (x1, x2, f a, g b) -- | @since 4.8.0.0 instance Bifunctor ((,,,,) x1 x2 x3) where - bimap f g ~(x1, x2, x3, a, b) = (x1, x2, x3, f a, g b) + bimap f g (x1, x2, x3, a, b) = (x1, x2, x3, f a, g b) -- | @since 4.8.0.0 instance Bifunctor ((,,,,,) x1 x2 x3 x4) where - bimap f g ~(x1, x2, x3, x4, a, b) = (x1, x2, x3, x4, f a, g b) + bimap f g (x1, x2, x3, x4, a, b) = (x1, x2, x3, x4, f a, g b) -- | @since 4.8.0.0 instance Bifunctor ((,,,,,,) x1 x2 x3 x4 x5) where - bimap f g ~(x1, x2, x3, x4, x5, a, b) = (x1, x2, x3, x4, x5, f a, g b) + bimap f g (x1, x2, x3, x4, x5, a, b) = (x1, x2, x3, x4, x5, f a, g b) -- | @since 4.8.0.0 View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ca5b02838abf8ad9d7a262396eb3df75... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ca5b02838abf8ad9d7a262396eb3df75... You're receiving this email because of your account on gitlab.haskell.org.