summaryrefslogtreecommitdiff
path: root/libraries/base/Control/Monad/Fix.hs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/base/Control/Monad/Fix.hs')
-rw-r--r--libraries/base/Control/Monad/Fix.hs10
1 files changed, 9 insertions, 1 deletions
diff --git a/libraries/base/Control/Monad/Fix.hs b/libraries/base/Control/Monad/Fix.hs
index c8a9ddab58..568568af84 100644
--- a/libraries/base/Control/Monad/Fix.hs
+++ b/libraries/base/Control/Monad/Fix.hs
@@ -29,7 +29,7 @@ import Data.Function ( fix )
import Data.Maybe
import Data.Monoid ( Dual(..), Sum(..), Product(..)
, First(..), Last(..), Alt(..) )
-import GHC.Base ( Monad, errorWithoutStackTrace, (.) )
+import GHC.Base ( Monad, NonEmpty(..), errorWithoutStackTrace, (.) )
import GHC.Generics
import GHC.List ( head, tail )
import GHC.ST
@@ -74,6 +74,14 @@ instance MonadFix [] where
[] -> []
(x:_) -> x : mfix (tail . f)
+-- | @since 4.9.0.0
+instance MonadFix NonEmpty where
+ mfix f = case fix (f . neHead) of
+ ~(x :| _) -> x :| mfix (neTail . f)
+ where
+ neHead ~(a :| _) = a
+ neTail ~(_ :| as) = as
+
-- | @since 2.01
instance MonadFix IO where
mfix = fixIO