summaryrefslogtreecommitdiff
path: root/libraries/base/Control
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/base/Control')
-rw-r--r--libraries/base/Control/Applicative.hs2
-rw-r--r--libraries/base/Control/Arrow.hs12
-rw-r--r--libraries/base/Control/Concurrent.hs9
-rw-r--r--libraries/base/Control/Monad/ST/Lazy/Imp.hs4
4 files changed, 14 insertions, 13 deletions
diff --git a/libraries/base/Control/Applicative.hs b/libraries/base/Control/Applicative.hs
index a2f342f83f..6770234926 100644
--- a/libraries/base/Control/Applicative.hs
+++ b/libraries/base/Control/Applicative.hs
@@ -96,7 +96,7 @@ instance Monad m => Functor (WrappedMonad m) where
fmap f (WrapMonad v) = WrapMonad (liftM f v)
instance Monad m => Applicative (WrappedMonad m) where
- pure = WrapMonad . return
+ pure = WrapMonad . pure
WrapMonad f <*> WrapMonad v = WrapMonad (f `ap` v)
instance MonadPlus m => Alternative (WrappedMonad m) where
diff --git a/libraries/base/Control/Arrow.hs b/libraries/base/Control/Arrow.hs
index 9d09544eeb..1cc6062516 100644
--- a/libraries/base/Control/Arrow.hs
+++ b/libraries/base/Control/Arrow.hs
@@ -93,16 +93,14 @@ class Category a => Arrow a where
-- | Send the first component of the input through the argument
-- arrow, and copy the rest unchanged to the output.
first :: a b c -> a (b,d) (c,d)
+ first = (*** id)
-- | A mirror image of 'first'.
--
-- The default definition may be overridden with a more efficient
-- version if desired.
second :: a b c -> a (d,b) (d,c)
- second f = arr swap >>> first f >>> arr swap
- where
- swap :: (x,y) -> (y,x)
- swap ~(x,y) = (y,x)
+ second = (id ***)
-- | Split the input between the two argument arrows and combine
-- their output. Note that this is in general not a functor.
@@ -110,7 +108,8 @@ class Category a => Arrow a where
-- The default definition may be overridden with a more efficient
-- version if desired.
(***) :: a b c -> a b' c' -> a (b,b') (c,c')
- f *** g = first f >>> second g
+ f *** g = first f >>> arr swap >>> first g >>> arr swap
+ where swap ~(x,y) = (y,x)
-- | Fanout: send the input to both argument arrows and combine
-- their output.
@@ -141,8 +140,6 @@ class Category a => Arrow a where
instance Arrow (->) where
arr f = f
- first f = f *** id
- second f = id *** f
-- (f *** g) ~(x,y) = (f x, g y)
-- sorry, although the above defn is fully H'98, nhc98 can't parse it.
(***) f g ~(x,y) = (f x, g y)
@@ -314,7 +311,6 @@ instance Arrow a => Applicative (ArrowMonad a) where
ArrowMonad f <*> ArrowMonad x = ArrowMonad (f &&& x >>> arr (uncurry id))
instance ArrowApply a => Monad (ArrowMonad a) where
- return x = ArrowMonad (arr (\_ -> x))
ArrowMonad m >>= f = ArrowMonad $
m >>> arr (\x -> let ArrowMonad h = f x in (h, ())) >>> app
diff --git a/libraries/base/Control/Concurrent.hs b/libraries/base/Control/Concurrent.hs
index 35248bfba3..1786c3ded3 100644
--- a/libraries/base/Control/Concurrent.hs
+++ b/libraries/base/Control/Concurrent.hs
@@ -3,6 +3,7 @@
, MagicHash
, UnboxedTuples
, ScopedTypeVariables
+ , RankNTypes
#-}
{-# OPTIONS_GHC -fno-warn-deprecations #-}
-- kludge for the Control.Concurrent.QSem, Control.Concurrent.QSemN
@@ -73,6 +74,7 @@ module Control.Concurrent (
-- $boundthreads
rtsSupportsBoundThreads,
forkOS,
+ forkOSWithUnmask,
isCurrentThreadBound,
runInBoundThread,
runInUnboundThread,
@@ -180,7 +182,7 @@ attribute will block all other threads.
-}
--- | fork a thread and call the supplied function when the thread is about
+-- | Fork a thread and call the supplied function when the thread is about
-- to terminate, with an exception or a returned value. The function is
-- called with asynchronous exceptions masked.
--
@@ -316,6 +318,11 @@ forkOS action0
return tid
| otherwise = failNonThreaded
+-- | Like 'forkIOWithUnmask', but the child thread is a bound thread,
+-- as with 'forkOS'.
+forkOSWithUnmask :: ((forall a . IO a -> IO a) -> IO ()) -> IO ThreadId
+forkOSWithUnmask io = forkOS (io unsafeUnmask)
+
-- | Returns 'True' if the calling thread is /bound/, that is, if it is
-- safe to use foreign libraries that rely on thread-local state from the
-- calling thread.
diff --git a/libraries/base/Control/Monad/ST/Lazy/Imp.hs b/libraries/base/Control/Monad/ST/Lazy/Imp.hs
index 55b28cfc9a..c99912e62d 100644
--- a/libraries/base/Control/Monad/ST/Lazy/Imp.hs
+++ b/libraries/base/Control/Monad/ST/Lazy/Imp.hs
@@ -71,13 +71,11 @@ instance Functor (ST s) where
(f r,new_s)
instance Applicative (ST s) where
- pure = return
+ pure a = ST $ \ s -> (a,s)
(<*>) = ap
instance Monad (ST s) where
- return a = ST $ \ s -> (a,s)
- m >> k = m >>= \ _ -> k
fail s = error s
(ST m) >>= k