Debug

lib/Debug.gob

Text for a programmer to read: a value as Turkey syntax would build it.

Show is text for the program's user and is written by hand. Debug is structural, and every type whose fields have it has it: the compiler derives an instance for each declared type that has none written, on demand. A derived instance prints the constructor and each field's own Debug, Pair(1, "a") or Point { x = 1, y = 2 }. A type with !Debug in its derive list prints as <Name> without reading a field, for state that may not be read outside a protocol, or storage that is never read at all.

What has no syntax prints as a placeholder: a function as <fun>, a field whose type mentions a type an existential hides as <hidden>, unless its Debug follows from the classes the constructor carries, and an object already on the path being printed as <cycle>, since only a cycle through objects can make printing a value loop.

class Debug a
fun debug : [Debug a] fun(a) -> String
fun dbg : [Debug a] fun(a) -> a

Returns x, having written debug(x) and a line break to standard error, after what standard output holds: a value can be shown from the middle of an expression. A failed write is not reported.

instance Debug Int
instance Debug Float

The shortest decimal that reads back as the same Float.

instance Debug Char
instance Debug Byte

There is no literal for a Byte, so it prints as the Int it holds.

instance Debug String
instance Debug Unit
instance Debug Prim.Ptr

An address, in hexadecimal.

instance Debug Prim.Atomic

The value it holds, read atomically.

instance Debug (Prim.Array a) : Debug a

Its elements, as an array literal.