Debug
Core
This module is useful while developing. Prefer these helpers over ad-hoc string building when inspecting values.
Values
toString
toString : a -> StringTurn any kind of value into a string.
Examples
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. It escapes characters so viewing data structures stays unambiguous.
inspect
inspect : String -> a -> aLog a tagged value to stdout, and then return the value.
Examples
1 + inspect "number" 1 -- equals 2, logs "number: 1"
List.length (inspect "start" []) -- equals 0, logs "start: []"It is often possible to sprinkle this around to see if values are what you expect.
todo
todo : String -> aThis is a placeholder for code that you will write later.
For example, if you are working with a large custom type and have partially completed a case expression, it may make sense to do this:
Examples
type Entity = Ship | Fish | Captain | Seagull
drawEntity entity =
case entity of
Ship ->
drawShip
Fish ->
drawFish
_ ->
Debug.todo "handle Captain and Seagull"If someone later calls drawEntity Captain, they get a clear runtime error pointing at unfinished code instead of a silent wrong answer.