Commit 0148a1c4 authored by bernalex's avatar bernalex Committed by Herbert Valerio Riedel
Browse files

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: bernalex's avatarAlexander Berntsen <alexander@plaimi.net>
Signed-off-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <hvr@gnu.org>
parent b0364249
...@@ -74,6 +74,9 @@ module Control.Monad ...@@ -74,6 +74,9 @@ module Control.Monad
, ap , ap
-- ** Strict monadic functions
, (<$!>)
) where ) where
import Data.Maybe import Data.Maybe
...@@ -311,6 +314,18 @@ is equivalent to ...@@ -311,6 +314,18 @@ is equivalent to
ap :: (Monad m) => m (a -> b) -> m a -> m b ap :: (Monad m) => m (a -> b) -> m a -> m b
ap = liftM2 id 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 -- Other MonadPlus functions
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
* Weaken RealFloat constraints on some `Data.Complex` functions * Weaken RealFloat constraints on some `Data.Complex` functions
* Add `Control.Monad.(<$!>)` as a strict version of `(<$>)`
## 4.7.0.0 *Apr 2014* ## 4.7.0.0 *Apr 2014*
* Bundled with GHC 7.8.1 * Bundled with GHC 7.8.1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment