diff options
Diffstat (limited to 'libraries/base/Control/Monad/Fix.hs')
| -rw-r--r-- | libraries/base/Control/Monad/Fix.hs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libraries/base/Control/Monad/Fix.hs b/libraries/base/Control/Monad/Fix.hs index 4862770f26..c8a9ddab58 100644 --- a/libraries/base/Control/Monad/Fix.hs +++ b/libraries/base/Control/Monad/Fix.hs @@ -62,60 +62,76 @@ class (Monad m) => MonadFix m where -- Instances of MonadFix for Prelude monads +-- | @since 2.01 instance MonadFix Maybe where mfix f = let a = f (unJust a) in a where unJust (Just x) = x unJust Nothing = errorWithoutStackTrace "mfix Maybe: Nothing" +-- | @since 2.01 instance MonadFix [] where mfix f = case fix (f . head) of [] -> [] (x:_) -> x : mfix (tail . f) +-- | @since 2.01 instance MonadFix IO where mfix = fixIO +-- | @since 2.01 instance MonadFix ((->) r) where mfix f = \ r -> let a = f a r in a +-- | @since 4.3.0.0 instance MonadFix (Either e) where mfix f = let a = f (unRight a) in a where unRight (Right x) = x unRight (Left _) = errorWithoutStackTrace "mfix Either: Left" +-- | @since 2.01 instance MonadFix (ST s) where mfix = fixST -- Instances of Data.Monoid wrappers +-- | @since 4.8.0.0 instance MonadFix Dual where mfix f = Dual (fix (getDual . f)) +-- | @since 4.8.0.0 instance MonadFix Sum where mfix f = Sum (fix (getSum . f)) +-- | @since 4.8.0.0 instance MonadFix Product where mfix f = Product (fix (getProduct . f)) +-- | @since 4.8.0.0 instance MonadFix First where mfix f = First (mfix (getFirst . f)) +-- | @since 4.8.0.0 instance MonadFix Last where mfix f = Last (mfix (getLast . f)) +-- | @since 4.8.0.0 instance MonadFix f => MonadFix (Alt f) where mfix f = Alt (mfix (getAlt . f)) -- Instances for GHC.Generics +-- | @since 4.9.0.0 instance MonadFix Par1 where mfix f = Par1 (fix (unPar1 . f)) +-- | @since 4.9.0.0 instance MonadFix f => MonadFix (Rec1 f) where mfix f = Rec1 (mfix (unRec1 . f)) +-- | @since 4.9.0.0 instance MonadFix f => MonadFix (M1 i c f) where mfix f = M1 (mfix (unM1. f)) +-- | @since 4.9.0.0 instance (MonadFix f, MonadFix g) => MonadFix (f :*: g) where mfix f = (mfix (fstP . f)) :*: (mfix (sndP . f)) where |
