summaryrefslogtreecommitdiff
path: root/libraries/base/Control/Monad
diff options
context:
space:
mode:
authorDavid Feuer <david.feuer@gmail.com>2017-02-05 19:43:31 -0500
committerDavid Feuer <David.Feuer@gmail.com>2017-02-05 19:43:32 -0500
commita2f39da0461b5da62a9020b0d98a1ce2765dd700 (patch)
tree38333e49d205beb1ee81cf51cd92ee3b9dcdad66 /libraries/base/Control/Monad
parent54b9b064fc7960a4dbad387481bc3a6496cc397f (diff)
downloadhaskell-a2f39da0461b5da62a9020b0d98a1ce2765dd700.tar.gz
Add liftA2 to Applicative class
* Make `liftA2` a method of `Applicative`. * Add explicit `liftA2` definitions to instances in `base`. * Add explicit invocations in `base`. Reviewers: ekmett, bgamari, RyanGlScott, austin, hvr Reviewed By: RyanGlScott Subscribers: ekmett, RyanGlScott, rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3031
Diffstat (limited to 'libraries/base/Control/Monad')
-rw-r--r--libraries/base/Control/Monad/ST/Lazy/Imp.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/libraries/base/Control/Monad/ST/Lazy/Imp.hs b/libraries/base/Control/Monad/ST/Lazy/Imp.hs
index 9883def001..67d5838356 100644
--- a/libraries/base/Control/Monad/ST/Lazy/Imp.hs
+++ b/libraries/base/Control/Monad/ST/Lazy/Imp.hs
@@ -142,6 +142,21 @@ instance Applicative (ST s) where
-- forces the (f x, s'') pair, then they must need
-- f or s''. To get s'', they need s'.
+ liftA2 f m n = ST $ \ s ->
+ let
+ {-# NOINLINE res1 #-}
+ -- See Note [Lazy ST and multithreading]
+ res1 = noDup (unST m s)
+ (x, s') = res1
+
+ {-# NOINLINE res2 #-}
+ res2 = noDup (unST n s')
+ (y, s'') = res2
+ in (f x y, s'')
+ -- We don't get to be strict in liftA2, but we clear out a
+ -- NOINLINE in comparison to the default definition, which may
+ -- help the simplifier.
+
m *> n = ST $ \s ->
let
{-# NOINLINE s' #-}