diff options
author | Herbert Valerio Riedel <hvr@gnu.org> | 2017-09-02 21:52:21 +0200 |
---|---|---|
committer | Herbert Valerio Riedel <hvr@gnu.org> | 2017-09-04 22:17:40 +0200 |
commit | cb3363e921fa58f9ad462d4bf5f4c819f910bf2a (patch) | |
tree | 4cc619bc037c0784894e619fe6a2f7399dd80419 /libraries/base/Control/Monad/Fix.hs | |
parent | 0ec4376902ee88a77a9f2ac9f3c03a4432455320 (diff) | |
download | haskell-cb3363e921fa58f9ad462d4bf5f4c819f910bf2a.tar.gz |
Move NonEmpty definition into GHC.Base
This is a preparatory refactoring for Semigroup=>Monoid
as it prevents a messy .hs-boot file which would interact
inconveniently with the buildsystem...
Diffstat (limited to 'libraries/base/Control/Monad/Fix.hs')
-rw-r--r-- | libraries/base/Control/Monad/Fix.hs | 10 |
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 |