[commit: ghc] master: Generalize traceM, traceShowM (fixes #10023) (39d83f2)

git at git.haskell.org git at git.haskell.org
Fri Jul 3 20:44:38 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/39d83f239d33b1d214bdb7f7b3ce94d76d3e1467/ghc

>---------------------------------------------------------------

commit 39d83f239d33b1d214bdb7f7b3ce94d76d3e1467
Author: RyanGlScott <ryan.gl.scott at gmail.com>
Date:   Fri Jul 3 19:37:06 2015 +0200

    Generalize traceM, traceShowM (fixes #10023)
    
    This generalizes the type signatures of `traceM` and `traceShowM` to
    use `Applicative` rather than `Monad`.
    
    Reviewers: austin, ekmett, hvr, bgamari
    
    Reviewed By: ekmett, hvr, bgamari
    
    Subscribers: thomie, bgamari
    
    Differential Revision: https://phabricator.haskell.org/D1029
    
    GHC Trac Issues: #10023


>---------------------------------------------------------------

39d83f239d33b1d214bdb7f7b3ce94d76d3e1467
 libraries/base/Debug/Trace.hs | 12 ++++++------
 libraries/base/changelog.md   |  3 +++
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/libraries/base/Debug/Trace.hs b/libraries/base/Debug/Trace.hs
index 16aba3c..26a19d8 100644
--- a/libraries/base/Debug/Trace.hs
+++ b/libraries/base/Debug/Trace.hs
@@ -149,9 +149,9 @@ traceShowId :: (Show a) => a -> a
 traceShowId a = trace (show a) a
 
 {-|
-Like 'trace' but returning unit in an arbitrary monad. Allows for convenient
-use in do-notation. Note that the application of 'trace' is not an action in the
-monad, as 'traceIO' is in the 'IO' monad.
+Like 'trace' but returning unit in an arbitrary 'Applicative' context. Allows
+for convenient use in do-notation. Note that the application of 'trace' is not
+an action in the 'Applicative' context, as 'traceIO' is in the 'IO' type.
 
 > ... = do
 >   x <- ...
@@ -161,8 +161,8 @@ monad, as 'traceIO' is in the 'IO' monad.
 
 @since 4.7.0.0
 -}
-traceM :: (Monad m) => String -> m ()
-traceM string = trace string $ return ()
+traceM :: (Applicative f) => String -> f ()
+traceM string = trace string $ pure ()
 
 {-|
 Like 'traceM', but uses 'show' on the argument to convert it to a 'String'.
@@ -175,7 +175,7 @@ Like 'traceM', but uses 'show' on the argument to convert it to a 'String'.
 
 @since 4.7.0.0
 -}
-traceShowM :: (Show a, Monad m) => a -> m ()
+traceShowM :: (Show a, Applicative f) => a -> f ()
 traceShowM = traceM . show
 
 -- | like 'trace', but additionally prints a call stack if one is
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index df691e3..363210d 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -37,6 +37,9 @@
 
   * `IO` now has a `Monoid` instance
 
+  * Generalize `Debug.Trace.{traceM, traceShowM}` from `Monad` to `Applicative`
+    (#10023)
+
 ## 4.8.1.0  *TBA*
 
   * Bundled with GHC 7.10.2



More information about the ghc-commits mailing list