Text input in Nyarna is of one of two types, Literal
or Space
.
These types are internal and cannot be referenced in user code.
Usually, text input is statically converted into the required scalar type.
For example, “false
” in an \if
expression is immediately converted to \Bool
.
However, the target type is not always available. For example, text can be in the body of a function, whose return type is inferred by Nyarna. In such cases, the return type of the function will use these internal types and conversion will happen at runtime, when the function is called.
Space
is the type of textual content consisting of only whitespace.
Literal
is used for all other textual content.
The significance of Space
is that it can be converted away implicitly when part of a concatenation.
The example shows how two record instances are created in the function things
.
They are separated by a newline, which is textual content and has the type \Space
.
If this is used in a context where textual content is not allowed, Nyarna will convert the space content away implicitly. This allows you to use whitespace for nice formatting in places where only record values are expected.
If, however, the same content is used in a place where textual content is allowed, the newline becomes \Text
.
The example shows this happening by assigning the function's return value to two variables where one allows \Text
while the other doesn't.
The second assignment will create an implicit conversion that strips away the whitespace.
Try it out!
Details
As discussed previously, an expression of type a can be used in a context where type b is expected if a ≤ b. If this relation does not exist for a and b, Nyarna may create an implicit conversion which replaces the original expression and has type c where c ≤ b.
Such conversions exist for removing \Space
, but also for transforming a \Sequence
expression into \Concat
.
If a \Sequence
is converted into a \Concat
, the separators (empty lines) are inserted into the content as \Space
.
These can then be stripped away if necessary.