This module contains functions for debugging pure functions. You
can't use functions like System.IO.putStrLn for this purpose because
they require changes to the type signature, but functions in this module
avoid this problem by being pure on their own.
Additionally, these functions produce compile-time warnings, if you leave them
in your code. Warnings help you to cleanup all debugging usages before
releasing.
ghci> foo = trace "I forgot trace in code"
<interactive>:4:7: warning: [-Wdeprecations]
In the use of ‘trace’ (imported from Relude):
"trace remains in code"
The following table briefly shows names and types of all functions in
this module.
⚠ NOTE: Use these functions only for local debugging
purposes. They break referential transparency, they are only useful
when you want to observe intermediate values of your pure functions
and to understand the behaviour locally. If you want to log debug
messages in your application, consider using a logging library
instead.
Trace function to print values while working a pure monad
(e.g. Maybe, State, etc.)
Example1 expression
>>> :{let action :: Maybe Int action = do x <- Just 3 traceM ("x: " ++ show x) y <- pure 12 traceM ("y: " ++ show y) pure (x*2 + y)in action:}x: 3y: 12Just 18
If you want to print a value with the Show instance instead, use traceShowM
Throw pure errors. Use this function only to when you are sure that this
branch of code execution is not possible. DO NOT USEerror as a normal
error handling mechanism.
Example1 expression
>>> error "oops"*** Exception: oopsCallStack (from HasCallStack): error, called at src/Relude/Debug.hs:289:11 in ......
⚠️CAUTION⚠️ Unlike Prelude version, error takes Text as an
argument. In case it used by mistake, the user will see the following:
Example2 expressions
>>> error ("oops" :: String)...... 'error' expects 'Text' but was given 'String'. Possible fixes: * Make sure OverloadedStrings extension is enabled * Use 'error (toText msg)' instead of 'error msg'...>>> error False...... 'error' works with 'Text' But given: Bool...