Widening type conversions, such as the conversion from int8 to int16, are performed implicitly. Other implicit type conversions can be introduced via a converter routine. 24.1. Converters A converter is like an ordinary proc except that it enhances the “implicitly convertible” type relation (see Section 17.3, “Convertible relation”): # bad style ahead: Nim is not C. converter toBool(x: int): bool = x != 0 if 4: echo "compiles" A converter can also be explicitly invoked for improved readability. Note that implicit converter chaining is not supported: If there is a converter from type A to type B and from type B to type C, the implicit conversion from A to C is not provided.
Converters should be introduced very carefully. Few use cases
are known where it adds clarity to the code rather than
obfuscation.