Types

Bach has null, boolean, number, string, array, object, and union types. Additionally, there is the Void type (there are no values of this type) and the Any type (all values are of this type). If you are wondering what the output type of your program is, you can always compose it with the type function, and you will get a string representation of the output type.

The following table demonstrates this: in the Program column, there are a number of Bach programs, each consisting of some expression followed by the type function. The Type column indicates the output type of the whole program. Here, it’s always Str because that is the output type of type. Finally, the Value column contains the strings representing the types of the various expressions.

ProgramTypeValueError
null typeStr"Null"
false typeStr"Bool"
true typeStr"Bool"
42 typeStr"Num"
0.3 typeStr"Num"
"Hello world!" typeStr"Str"
[] typeStr"Arr<>"
{} typeStr"Obj<Void>"
for Any def f Num|Str as 0 ok f typeStr"Num|Str"
for Any def f Any as null ok f typeStr"Any"