summaryrefslogtreecommitdiff
path: root/libraries/base/Control
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-01-25 10:22:29 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-01-27 17:39:49 -0500
commit5d6009a88156ad42b387383e41a7e0707c7f06a4 (patch)
treed2384dfb0328e4b6f31fc886e2b1732cfd31f157 /libraries/base/Control
parent93ae0e2a95ff57b587d673aa8946ee710012b37e (diff)
downloadhaskell-5d6009a88156ad42b387383e41a7e0707c7f06a4.tar.gz
Add instances for GHC.Tuple.Solo
The `Applicative` instance is the most important one (for array/vector/sequence indexing purposes), but it deserves all the usual ones. T12545 does silly 1% wibbles both ways, it seems, maybe depending on architecture. Metric Increase: T12545 Metric Decrease: T12545
Diffstat (limited to 'libraries/base/Control')
-rw-r--r--libraries/base/Control/Monad/Fix.hs6
-rw-r--r--libraries/base/Control/Monad/Zip.hs6
2 files changed, 12 insertions, 0 deletions
diff --git a/libraries/base/Control/Monad/Fix.hs b/libraries/base/Control/Monad/Fix.hs
index 96133777be..b54ee66531 100644
--- a/libraries/base/Control/Monad/Fix.hs
+++ b/libraries/base/Control/Monad/Fix.hs
@@ -33,6 +33,7 @@ import Data.Ord ( Down(..) )
import GHC.Base ( Monad, NonEmpty(..), errorWithoutStackTrace, (.) )
import GHC.Generics
import GHC.List ( head, tail )
+import GHC.Tuple (Solo (..))
import Control.Monad.ST.Imp
import System.IO
@@ -63,6 +64,11 @@ class (Monad m) => MonadFix m where
-- Instances of MonadFix for Prelude monads
+-- | @since 4.15
+instance MonadFix Solo where
+ mfix f = let a = f (unSolo a) in a
+ where unSolo (Solo x) = x
+
-- | @since 2.01
instance MonadFix Maybe where
mfix f = let a = f (unJust a) in a
diff --git a/libraries/base/Control/Monad/Zip.hs b/libraries/base/Control/Monad/Zip.hs
index dc192bfc81..36ebeb9985 100644
--- a/libraries/base/Control/Monad/Zip.hs
+++ b/libraries/base/Control/Monad/Zip.hs
@@ -25,6 +25,7 @@ import Data.Ord ( Down(..) )
import Data.Proxy
import qualified Data.List.NonEmpty as NE
import GHC.Generics
+import GHC.Tuple (Solo (..))
-- | Instances should satisfy the laws:
--
@@ -71,6 +72,11 @@ 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
+ munzip (Solo (a, b)) = (Solo a, Solo b)
+
-- | @since 4.8.0.0
instance MonadZip Dual where
-- Cannot use coerce, it's unsafe