Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module can be useful while developing an application. It should not be used in production.
Debugging
toString :: Show a => a -> Text Source #
Turn any Show
able kind of value into a string.
toString 42 == "42" toString [1,2] == "[1,2]" toString ('a', "cat", 13) == "('a', \"cat\", 13)" toString "he said, \"hi\"" == "\"he said, \\\"hi\\\"\""
Notice that with strings, this is not the identity
function. Ultimately it's
down to the value's Show
instance, but for strings this typically escapes
characters. If you say toString "he said, \"hi\""
it will show "he said,
\"hi\""
rather than he said, "hi"
.
log :: Show a => Text -> a -> a Source #
Log a tagged value on the developer console, and then return the value.
1 + log "number" 1 -- equals 2, logs "number: 1" length (log "start" []) -- equals 0, logs "start: []"
It is often possible to sprinkle this around to see if values are what you expect. It is kind of old-school to do it this way, but it works!
todo :: HasCallStack => Text -> a Source #
This is a placeholder for code that you will write later.
For example, if you are working with a large union type and have partially completed a case expression, it may make sense to do this:
type Entity = Ship | Fish | Captain | Seagull drawEntity entity = case entity of Ship -> ... Fish -> ... _ -> Debug.todo "handle Captain and Seagull"
When you call this it throws an exception with the message you give. That exception is catchable... but don't.