summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBodigrim <andrew.lelechenko@gmail.com>2022-12-11 01:04:09 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-12-11 12:26:55 -0500
commitbfd7c1e653c207dd5dea599f16ee4afad03f2ea5 (patch)
tree7015f7cc86702e0147b089c618dfdf19659c74c8
parentb3e98a926ac05b8e59e3b31b74b019d4ecb462f6 (diff)
downloadhaskell-bfd7c1e653c207dd5dea599f16ee4afad03f2ea5.tar.gz
Document that Bifunctor instances for tuples are lawful only up to laziness
-rw-r--r--libraries/base/Data/Bifunctor.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/libraries/base/Data/Bifunctor.hs b/libraries/base/Data/Bifunctor.hs
index f014e5d3d4..217c4a2681 100644
--- a/libraries/base/Data/Bifunctor.hs
+++ b/libraries/base/Data/Bifunctor.hs
@@ -120,8 +120,17 @@ class (forall a. Functor (p a)) => Bifunctor p where
second = bimap id
-
--- | @since 4.8.0.0
+-- | Class laws for tuples hold only up to laziness. Both
+-- 'first' 'id' and 'second' 'id' are lazier than 'id' (and 'fmap' 'id'):
+--
+-- >>> first id (undefined :: (Int, Word)) `seq` ()
+-- ()
+-- >>> second id (undefined :: (Int, Word)) `seq` ()
+-- ()
+-- >>> id (undefined :: (Int, Word)) `seq` ()
+-- *** Exception: Prelude.undefined
+--
+-- @since 4.8.0.0
instance Bifunctor (,) where
bimap f g ~(a, b) = (f a, g b)