diff options
author | Alexander Berntsen <alexander@plaimi.net> | 2014-05-13 10:50:30 +0200 |
---|---|---|
committer | Herbert Valerio Riedel <hvr@gnu.org> | 2014-05-14 09:16:41 +0200 |
commit | 0148a1c416e42a7d7c9ff3624a0640963bfe0012 (patch) | |
tree | 89f3937634d36eabf57691366b3489e9571caa60 | |
parent | b0364249b76b0091d83cae3b658ac3ed725ba5fc (diff) | |
download | haskell-0148a1c416e42a7d7c9ff3624a0640963bfe0012.tar.gz |
Add strict ver. of (<$>): (<$!>) to Control.Monad
A strict (<$>) has been proposed numerous times. The first time
around[1] by Johan Tibell, and the last time around[2] by David
Luposchainsky. David's thread was able to avoid The Bikeshed Monster,
and his (<$!>) proposal received unanimous +1s all around.
This addresses #9099.
[1]: http://www.haskell.org/pipermail/libraries/2013-November/021728.html
[2]: http://www.haskell.org/pipermail/libraries/2014-April/022864.html
Authored-by: Alexander Berntsen <alexander@plaimi.net>
Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
-rw-r--r-- | libraries/base/Control/Monad.hs | 15 | ||||
-rw-r--r-- | libraries/base/changelog.md | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/libraries/base/Control/Monad.hs b/libraries/base/Control/Monad.hs index 19c9a87bde..00c1fdda37 100644 --- a/libraries/base/Control/Monad.hs +++ b/libraries/base/Control/Monad.hs @@ -74,6 +74,9 @@ module Control.Monad , ap + -- ** Strict monadic functions + + , (<$!>) ) where import Data.Maybe @@ -311,6 +314,18 @@ is equivalent to ap :: (Monad m) => m (a -> b) -> m a -> m b ap = liftM2 id +infixl 4 <$!> + +-- | Strict version of 'Data.Functor.<$>'. +-- +-- /Since: 4.7.1.0/ +(<$!>) :: Monad m => (a -> b) -> m a -> m b +{-# INLINE (<$!>) #-} +f <$!> m = do + x <- m + let z = f x + z `seq` return z + -- ----------------------------------------------------------------------------- -- Other MonadPlus functions diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md index c561165024..4efb1216e1 100644 --- a/libraries/base/changelog.md +++ b/libraries/base/changelog.md @@ -12,6 +12,8 @@ * Weaken RealFloat constraints on some `Data.Complex` functions + * Add `Control.Monad.(<$!>)` as a strict version of `(<$>)` + ## 4.7.0.0 *Apr 2014* * Bundled with GHC 7.8.1 |