Skip to content
Snippets Groups Projects
Unverified Commit 90424a46 authored by Naïm Favier's avatar Naïm Favier
Browse files

ghc-internal: add MonadFix instance for (,)

Closes ghc/ghc#24288, implements CLC
proposal https://github.com/haskell/core-libraries-committee/issues/238.

Adds a MonadFix instance for tuples, permitting value recursion in the
"native" writer monad and bringing consistency with the existing
instance for transformers's WriterT (and, to a lesser extent, for Solo).

See the CLC thread for proofs of the MonadFix laws.
parent 8bbe12f2
No related branches found
No related tags found
No related merge requests found
Pipeline #89956 failed
......@@ -30,13 +30,13 @@ module Control.Monad.Fix (
import Data.Either
import Data.Function ( fix )
import Data.Maybe
import Data.Monoid ( Dual(..), Sum(..), Product(..)
import Data.Monoid ( Monoid, Dual(..), Sum(..), Product(..)
, First(..), Last(..), Alt(..), Ap(..) )
import Data.Ord ( Down(..) )
import Data.Tuple ( Solo(..), snd )
import GHC.Base ( Monad, NonEmpty(..), errorWithoutStackTrace, (.) )
import GHC.Generics
import GHC.List ( head, drop )
import GHC.Tuple (Solo (..))
import Control.Monad.ST.Imp
import System.IO
......@@ -72,6 +72,10 @@ instance MonadFix Solo where
mfix f = let a = f (unSolo a) in a
where unSolo (MkSolo x) = x
-- | @since 4.20
instance Monoid a => MonadFix ((,) a) where
mfix f = let a = f (snd a) in a
-- | @since 2.01
instance MonadFix Maybe where
mfix f = let a = f (unJust a) in a
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment