Safe Haskell | None |
---|

This module exposes some useful tracing functions that should have been exported by Debug.Trace.

Feel free to copy&paste these functions into modules that need them, that may be easier to remove/clean up than adding a cabal dependency.

- traceId :: Show a => String -> a -> a
- traceIdVia :: Show b => (a -> b) -> String -> a -> a
- traceAround :: (Show i, Show o) => String -> (i -> o) -> i -> o
- tracePutStrLn :: Monad m => String -> m ()
- tracePrint :: (Show a, Monad m) => a -> m ()
- trace :: String -> a -> a

# Documentation

Generate an identity function that has the side-effect of showing the value that passes through it.

Examples:

traceId "x,y = " (x, y)

:: Show b | |

=> (a -> b) | Function to preprocess the value before showing it |

-> String | Prefix string to use before showing the result value |

-> a | |

-> a |

Generate an identity function that has the side-effect of tracing the value that passes through it by first processing it and then showing the result.

Examples:

traceIdVia (take 5) "First 5 sorted elements of: " result

fmap (traceIdVia objName "The object we got") . receiveObject

traceAround :: (Show i, Show o) => String -> (i -> o) -> i -> oSource

Convert a pure function to one that also has a side effect of tracing the value of the input and output values that pass through the function.

Examples:

traceAround "filterEntries" filterEntries entries

tracePutStrLn :: Monad m => String -> m ()Source

tracePrint :: (Show a, Monad m) => a -> m ()Source

The `trace`

function outputs the trace message given as its first argument,
before returning the second argument as its result.

For example, this returns the value of `f x`

but first outputs the message.

trace ("calling f with x = " ++ show x) (f x)

The `trace`

function should *only* be used for debugging, or for monitoring
execution. The function is not referentially transparent: its type indicates
that it is a pure function but it has the side effect of outputting the
trace message.