Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

11 changed files:

Changes:

  • compiler/GHC/Data/IOEnv.hs
    ... ... @@ -45,7 +45,7 @@ import Data.IORef ( IORef, newIORef, readIORef, writeIORef, modifyIORef,
    45 45
                               atomicModifyIORef, atomicModifyIORef' )
    
    46 46
     import System.IO.Unsafe ( unsafeInterleaveIO )
    
    47 47
     import System.IO        ( fixIO )
    
    48
    -import Control.Monad
    
    48
    +import Control.Monad    ( MonadPlus )
    
    49 49
     import Control.Monad.Trans.Reader
    
    50 50
     import Control.Monad.Catch (MonadCatch, MonadMask, MonadThrow)
    
    51 51
     import GHC.Utils.Monad
    

  • libraries/base/changelog.md
    ... ... @@ -6,6 +6,7 @@
    6 6
       * Fix issues with toRational for types capable to represent infinite and not-a-number values ([CLC proposal #338](https://github.com/haskell/core-libraries-committee/issues/338))
    
    7 7
       * Modify the implementation of `Data.List.sortOn` to use `(>)` instead of `compare`. ([CLC proposal #332](https://github.com/haskell/core-libraries-committee/issues/332))
    
    8 8
       * `GHC.Exts.IOPort#` and its related operations have been removed  ([CLC #213](https://github.com/haskell/core-libraries-committee/issues/213))
    
    9
    +  * Add `thenA` and `thenM`. ([CLC proposal #351](https://github.com/haskell/core-libraries-committee/issues/351))
    
    9 10
       * Fix bug where `naturalAndNot` was incorrectly truncating results ([CLC proposal #350](github.com/haskell/core-libraries-committee/issues/350))
    
    10 11
       * Remove extra laziness from `Data.Bifunctor.Bifunctor` instances for all tuples to have the same laziness as their `Data.Functor.Functor` counterparts (i.e. they became more strict than before) ([CLC proposal #339](https://github.com/haskell/core-libraries-committee/issues/339))
    
    11 12
       * Adjust the strictness of `Data.List.iterate'` to be more reasonable: every element of the output list is forced to WHNF when the `(:)` containing it is forced. ([CLC proposal #335)](https://github.com/haskell/core-libraries-committee/issues/335)
    

  • libraries/base/src/Control/Applicative.hs
    ... ... @@ -49,6 +49,7 @@ module Control.Applicative (
    49 49
         liftA, liftA3,
    
    50 50
         optional,
    
    51 51
         asum,
    
    52
    +    thenA,
    
    52 53
         ) where
    
    53 54
     
    
    54 55
     import GHC.Internal.Control.Category hiding ((.), id)
    

  • libraries/base/src/Control/Monad.hs
    ... ... @@ -57,6 +57,7 @@ module Control.Monad
    57 57
          liftM4,
    
    58 58
          liftM5,
    
    59 59
          ap,
    
    60
    +     thenM,
    
    60 61
          -- **  Strict monadic functions
    
    61 62
          (<$!>)
    
    62 63
          ) where
    

  • libraries/ghc-internal/src/GHC/Internal/Base.hs
    ... ... @@ -1223,6 +1223,9 @@ class Functor f => Applicative f where
    1223 1223
     --
    
    1224 1224
     -- As such this function may be used to implement a `Functor` instance from an `Applicative` one.
    
    1225 1225
     --
    
    1226
    +-- This function can be used to define `fmap = liftA`, if `Applicative` is already
    
    1227
    +-- defined for a data type.
    
    1228
    +--
    
    1226 1229
     -- ==== __Examples__
    
    1227 1230
     -- Using the Applicative instance for Lists:
    
    1228 1231
     --
    
    ... ... @@ -1233,7 +1236,6 @@ class Functor f => Applicative f where
    1233 1236
     --
    
    1234 1237
     -- >>> liftA (+1) (Just 3)
    
    1235 1238
     -- Just 4
    
    1236
    -
    
    1237 1239
     liftA :: Applicative f => (a -> b) -> f a -> f b
    
    1238 1240
     liftA f a = pure f <*> a
    
    1239 1241
     -- Caution: since this may be used for `fmap`, we can't use the obvious
    
    ... ... @@ -1253,6 +1255,18 @@ liftA3 f a b c = liftA2 f a b <*> c
    1253 1255
     {-# SPECIALISE liftA3 :: (a1->a2->a3->r) ->
    
    1254 1256
                                     Maybe a1 -> Maybe a2 -> Maybe a3 -> Maybe r #-}
    
    1255 1257
     
    
    1258
    +-- | Sequence two `Applicative` actions, discarding the result of the first one.
    
    1259
    +--
    
    1260
    +-- Defined as `thenA fa fb = (id <$ fa) <*> fb`.
    
    1261
    +--
    
    1262
    +-- This can be used to explicitly define `(*>) = thenA`, which is the default
    
    1263
    +-- definition.
    
    1264
    +--
    
    1265
    +-- @since 4.23.0.0
    
    1266
    +thenA :: Applicative f => f a -> f b -> f b
    
    1267
    +thenA fa fb = (id <$ fa) <*> fb
    
    1268
    +{-# INLINEABLE thenA #-}
    
    1269
    +
    
    1256 1270
     -- | The 'join' function is the conventional monad join operator. It
    
    1257 1271
     -- is used to remove one level of monadic structure, projecting its
    
    1258 1272
     -- bound argument into the outer level.
    
    ... ... @@ -1453,12 +1467,18 @@ similar problems in nofib.
    1453 1467
     
    
    1454 1468
     -- | Promote a function to a monad.
    
    1455 1469
     -- This is equivalent to 'fmap' but specialised to Monads.
    
    1470
    +--
    
    1471
    +-- This function can be used to define `fmap = liftM`, if `Monad` is already
    
    1472
    +-- defined for a data type.
    
    1456 1473
     liftM   :: (Monad m) => (a1 -> r) -> m a1 -> m r
    
    1457 1474
     liftM f m1              = do { x1 <- m1; return (f x1) }
    
    1458 1475
     
    
    1459 1476
     -- | Promote a function to a monad, scanning the monadic arguments from
    
    1460 1477
     -- left to right.
    
    1461 1478
     --
    
    1479
    +-- This function can be used to define `liftA2 = liftM2`, if `Monad` is already
    
    1480
    +-- defined for a data type.
    
    1481
    +--
    
    1462 1482
     -- ==== __Examples__
    
    1463 1483
     --
    
    1464 1484
     -- >>> liftM2 (+) [0,1] [0,2]
    
    ... ... @@ -1514,6 +1534,9 @@ is equivalent to
    1514 1534
     
    
    1515 1535
     > liftM<n> f x1 x2 ... xn
    
    1516 1536
     
    
    1537
    +This function can be used to define `(<*>) = ap`, if `Monad` is already
    
    1538
    +defined for a data type.
    
    1539
    +
    
    1517 1540
     ==== __Examples__
    
    1518 1541
     
    
    1519 1542
     >>> pure (\x y z -> x + y * z) `ap` Just 1 `ap` Just 5 `ap` Just 10
    
    ... ... @@ -1527,6 +1550,17 @@ ap m1 m2 = do { x1 <- m1; x2 <- m2; return (x1 x2) }
    1527 1550
     {-# SPECIALISE ap :: IO (a -> b) -> IO a -> IO b #-}
    
    1528 1551
     {-# SPECIALISE ap :: Maybe (a -> b) -> Maybe a -> Maybe b #-}
    
    1529 1552
     
    
    1553
    +-- | Sequence two monadic actions, discarding the result of the first one.
    
    1554
    +--
    
    1555
    +-- Defined as `thenM ma mb = ma >>= const mb`.
    
    1556
    +--
    
    1557
    +-- This can be used to define `(*>) = thenM`.
    
    1558
    +--
    
    1559
    +-- @since 4.23.0.0
    
    1560
    +thenM :: (Monad m) => m a -> m b -> m b
    
    1561
    +thenM ma mb = ma >>= const mb
    
    1562
    +{-# INLINEABLE thenM #-}
    
    1563
    +
    
    1530 1564
     -- instances for Prelude types
    
    1531 1565
     
    
    1532 1566
     -- | @since base-2.01
    

  • libraries/ghc-internal/src/GHC/Internal/Control/Monad.hs
    ... ... @@ -71,6 +71,8 @@ module GHC.Internal.Control.Monad
    71 71
     
    
    72 72
         , ap
    
    73 73
     
    
    74
    +    , thenM
    
    75
    +
    
    74 76
         -- ** Strict monadic functions
    
    75 77
     
    
    76 78
         , (<$!>)
    

  • testsuite/tests/interface-stability/base-exports.stdout
    ... ... @@ -34,6 +34,7 @@ module Control.Applicative where
    34 34
       liftA :: forall (f :: * -> *) a b. Applicative f => (a -> b) -> f a -> f b
    
    35 35
       liftA3 :: forall (f :: * -> *) a b c d. Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
    
    36 36
       optional :: forall (f :: * -> *) a. Alternative f => f a -> f (GHC.Internal.Maybe.Maybe a)
    
    37
    +  thenA :: forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    
    37 38
     
    
    38 39
     module Control.Arrow where
    
    39 40
       -- Safety: Safe
    
    ... ... @@ -483,6 +484,7 @@ module Control.Monad where
    483 484
       replicateM_ :: forall (m :: * -> *) a. GHC.Internal.Base.Applicative m => GHC.Internal.Types.Int -> m a -> m ()
    
    484 485
       sequence :: forall (t :: * -> *) (m :: * -> *) a. (GHC.Internal.Data.Traversable.Traversable t, Monad m) => t (m a) -> m (t a)
    
    485 486
       sequence_ :: forall (t :: * -> *) (m :: * -> *) a. (GHC.Internal.Data.Foldable.Foldable t, Monad m) => t (m a) -> m ()
    
    487
    +  thenM :: forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    
    486 488
       unless :: forall (f :: * -> *). GHC.Internal.Base.Applicative f => GHC.Internal.Types.Bool -> f () -> f ()
    
    487 489
       void :: forall (f :: * -> *) a. Functor f => f a -> f ()
    
    488 490
       when :: forall (f :: * -> *). GHC.Internal.Base.Applicative f => GHC.Internal.Types.Bool -> f () -> f ()
    

  • testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
    ... ... @@ -34,6 +34,7 @@ module Control.Applicative where
    34 34
       liftA :: forall (f :: * -> *) a b. Applicative f => (a -> b) -> f a -> f b
    
    35 35
       liftA3 :: forall (f :: * -> *) a b c d. Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
    
    36 36
       optional :: forall (f :: * -> *) a. Alternative f => f a -> f (GHC.Internal.Maybe.Maybe a)
    
    37
    +  thenA :: forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    
    37 38
     
    
    38 39
     module Control.Arrow where
    
    39 40
       -- Safety: Safe
    
    ... ... @@ -483,6 +484,7 @@ module Control.Monad where
    483 484
       replicateM_ :: forall (m :: * -> *) a. GHC.Internal.Base.Applicative m => GHC.Internal.Types.Int -> m a -> m ()
    
    484 485
       sequence :: forall (t :: * -> *) (m :: * -> *) a. (GHC.Internal.Data.Traversable.Traversable t, Monad m) => t (m a) -> m (t a)
    
    485 486
       sequence_ :: forall (t :: * -> *) (m :: * -> *) a. (GHC.Internal.Data.Foldable.Foldable t, Monad m) => t (m a) -> m ()
    
    487
    +  thenM :: forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    
    486 488
       unless :: forall (f :: * -> *). GHC.Internal.Base.Applicative f => GHC.Internal.Types.Bool -> f () -> f ()
    
    487 489
       void :: forall (f :: * -> *) a. Functor f => f a -> f ()
    
    488 490
       when :: forall (f :: * -> *). GHC.Internal.Base.Applicative f => GHC.Internal.Types.Bool -> f () -> f ()
    

  • testsuite/tests/interface-stability/base-exports.stdout-mingw32
    ... ... @@ -34,6 +34,7 @@ module Control.Applicative where
    34 34
       liftA :: forall (f :: * -> *) a b. Applicative f => (a -> b) -> f a -> f b
    
    35 35
       liftA3 :: forall (f :: * -> *) a b c d. Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
    
    36 36
       optional :: forall (f :: * -> *) a. Alternative f => f a -> f (GHC.Internal.Maybe.Maybe a)
    
    37
    +  thenA :: forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    
    37 38
     
    
    38 39
     module Control.Arrow where
    
    39 40
       -- Safety: Safe
    
    ... ... @@ -483,6 +484,7 @@ module Control.Monad where
    483 484
       replicateM_ :: forall (m :: * -> *) a. GHC.Internal.Base.Applicative m => GHC.Internal.Types.Int -> m a -> m ()
    
    484 485
       sequence :: forall (t :: * -> *) (m :: * -> *) a. (GHC.Internal.Data.Traversable.Traversable t, Monad m) => t (m a) -> m (t a)
    
    485 486
       sequence_ :: forall (t :: * -> *) (m :: * -> *) a. (GHC.Internal.Data.Foldable.Foldable t, Monad m) => t (m a) -> m ()
    
    487
    +  thenM :: forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    
    486 488
       unless :: forall (f :: * -> *). GHC.Internal.Base.Applicative f => GHC.Internal.Types.Bool -> f () -> f ()
    
    487 489
       void :: forall (f :: * -> *) a. Functor f => f a -> f ()
    
    488 490
       when :: forall (f :: * -> *). GHC.Internal.Base.Applicative f => GHC.Internal.Types.Bool -> f () -> f ()
    

  • testsuite/tests/interface-stability/base-exports.stdout-ws-32
    ... ... @@ -34,6 +34,7 @@ module Control.Applicative where
    34 34
       liftA :: forall (f :: * -> *) a b. Applicative f => (a -> b) -> f a -> f b
    
    35 35
       liftA3 :: forall (f :: * -> *) a b c d. Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
    
    36 36
       optional :: forall (f :: * -> *) a. Alternative f => f a -> f (GHC.Internal.Maybe.Maybe a)
    
    37
    +  thenA :: forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    
    37 38
     
    
    38 39
     module Control.Arrow where
    
    39 40
       -- Safety: Safe
    
    ... ... @@ -483,6 +484,7 @@ module Control.Monad where
    483 484
       replicateM_ :: forall (m :: * -> *) a. GHC.Internal.Base.Applicative m => GHC.Internal.Types.Int -> m a -> m ()
    
    484 485
       sequence :: forall (t :: * -> *) (m :: * -> *) a. (GHC.Internal.Data.Traversable.Traversable t, Monad m) => t (m a) -> m (t a)
    
    485 486
       sequence_ :: forall (t :: * -> *) (m :: * -> *) a. (GHC.Internal.Data.Foldable.Foldable t, Monad m) => t (m a) -> m ()
    
    487
    +  thenM :: forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    
    486 488
       unless :: forall (f :: * -> *). GHC.Internal.Base.Applicative f => GHC.Internal.Types.Bool -> f () -> f ()
    
    487 489
       void :: forall (f :: * -> *) a. Functor f => f a -> f ()
    
    488 490
       when :: forall (f :: * -> *). GHC.Internal.Base.Applicative f => GHC.Internal.Types.Bool -> f () -> f ()
    

  • testsuite/tests/profiling/should_run/callstack001.stdout
    1
    -["GHC.Internal.TopHandler.runMainIO1 (<no location info>)","Main.main (callstack001.hs:17:8-21)","Main.mapM (callstack001.hs:10:13-17)","Main.mapM.go (callstack001.hs:(12,21)-(15,25))","Main.mapM.go (callstack001.hs:13:17-19)","Main.f (callstack001.hs:7:7-49)","Main.f (callstack001.hs:7:10-35)","GHC.Internal.Base.>>= (libraries/ghc-internal/src/GHC/Internal/Base.hs:1350:5-55)","GHC.Internal.Base.$fMonadIO1 (<no location info>)","GHC.Internal.Stack.CCS.currentCallStack (libraries/ghc-internal/src/GHC/Internal/Stack/CCS.hsc:126:1-16)","GHC.Internal.Stack.CCS.currentCallStack1 (<no location info>)"]
    
    2
    -["GHC.Internal.TopHandler.runMainIO1 (<no location info>)","Main.main (callstack001.hs:17:8-21)","Main.mapM (callstack001.hs:10:13-17)","Main.mapM.go (callstack001.hs:(12,21)-(15,25))","GHC.Internal.Base.>>= (libraries/ghc-internal/src/GHC/Internal/Base.hs:1350:5-55)","GHC.Internal.Base.$fMonadIO1 (<no location info>)","GHC.Internal.Stack.CCS.currentCallStack (libraries/ghc-internal/src/GHC/Internal/Stack/CCS.hsc:126:1-16)","GHC.Internal.Stack.CCS.currentCallStack1 (<no location info>)"]
    1
    +["GHC.Internal.TopHandler.runMainIO1 (<no location info>)","Main.main (callstack001.hs:17:8-21)","Main.mapM (callstack001.hs:10:13-17)","Main.mapM.go (callstack001.hs:(12,21)-(15,25))","Main.mapM.go (callstack001.hs:13:17-19)","Main.f (callstack001.hs:7:7-49)","Main.f (callstack001.hs:7:10-35)","GHC.Internal.Base.>>= (libraries/ghc-internal/src/GHC/Internal/Base.hs:1364:5-55)","GHC.Internal.Base.$fMonadIO1 (<no location info>)","GHC.Internal.Stack.CCS.currentCallStack (libraries/ghc-internal/src/GHC/Internal/Stack/CCS.hsc:126:1-16)","GHC.Internal.Stack.CCS.currentCallStack1 (<no location info>)"]
    
    2
    +["GHC.Internal.TopHandler.runMainIO1 (<no location info>)","Main.main (callstack001.hs:17:8-21)","Main.mapM (callstack001.hs:10:13-17)","Main.mapM.go (callstack001.hs:(12,21)-(15,25))","GHC.Internal.Base.>>= (libraries/ghc-internal/src/GHC/Internal/Base.hs:1364:5-55)","GHC.Internal.Base.$fMonadIO1 (<no location info>)","GHC.Internal.Stack.CCS.currentCallStack (libraries/ghc-internal/src/GHC/Internal/Stack/CCS.hsc:126:1-16)","GHC.Internal.Stack.CCS.currentCallStack1 (<no location info>)"]