Next: Operators, Up: Marsyas Expression Syntax
There are a few instances where type coercion may take place. Binary operators such as + require two values of the same type. Natural numbers are therefore promoted to reals in such a situation (1 + 1.0 := ((real)1) + 1.0). Real numbers are not converted to naturals in any case. For string concatenation using the + operator, any type concatenated to a string is converted to a string type (1+'2' := '12').
Type coercion also affects function parameters. For instance, the function Real.cos(real) when used as Real.cos(1) would result in a type error as 1 is interpreted to be a natural value. Instead the function call is converted to Real.cos((real)1).
Note that there is a performance penalty for coercion as slight as it may be.