diff options
author | RyanGlScott <ryan.gl.scott@gmail.com> | 2015-07-03 19:37:06 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-07-03 22:44:50 +0200 |
commit | 39d83f239d33b1d214bdb7f7b3ce94d76d3e1467 (patch) | |
tree | 6b51b4df72f15ae7deccb84e6ee4d8db028f79e7 | |
parent | 8b55788cae54c9b79b9fc973e9e77f0de1ccc49b (diff) | |
download | haskell-39d83f239d33b1d214bdb7f7b3ce94d76d3e1467.tar.gz |
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
-rw-r--r-- | libraries/base/Debug/Trace.hs | 12 | ||||
-rw-r--r-- | 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 16aba3c122..26a19d8f71 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 df691e3843..363210dbc6 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 |