Inferring types

Everything in Red has a type, but as you noticed you don't have to declare that type yourself, in contrast to languages such as Java, C#, or C++. We could say that Red is a dynamic, high-level scripting language such as Python or Ruby, and so doesn't need explicit typing. This is partly true, but nevertheless Red can be compiled to native code, so the compiler needs to know the types of all words.

As many other languages do, the Red compiler infers the types. This type inference can become very complicated, leading to slow compilation. To remedy this, Red has chosen for a hybrid type-system (as did Crystal, Dart, and Scala), also called optional or gradual typing. This means that types can be omitted. But when they are used, ...

Get Learn Red - Fundamentals of Red now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.