5.2 Expressions and Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.2.1 Unary Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.2.2 Binary Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.3 Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.5 Function Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.5.1 Variable Assignment from Functions . . . . . . . . . . . . . . . . . . . . . . . 14
6 Classes 14
7 Standard Library 15
7.1 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
7.2 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
7.3 range() and print() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
7.4 Casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
8 Sample Code 16
1 Overview of Coral
The Coral programming language is an imperative and functional scripting language inspired by
Python, with optional static typing used to enforce type safety and optimize code. It roughly aims
to be to Python as TypeScript is to JavaScript. The basic syntax is identical to Python, and any
valid Coral program can also be run by a Python interpreter. Coral also uses the newly introduced
optional static typing syntax found in Python 3.7, allowing variables and function declarations to be
tagged with specific types. Unlike in Python, these types are not merely cosmetic. The Coral typing
system will be checked and enforced at compile time and runtime, preventing errors due to invalid
type usage in large codebases, and will also be used to optimize the performance of the language
where possible. The goal is to create a language that is as convenient as Python and as safe as an
explicitly typed language with superior performance to existing scripting languages.
Our goals are:
• Python-style syntax with all its usual convenience, including runtime typing where types are
not explicitly specified.
• Type safety where desired, with type specifiers on variables and functions enforcing correct
usage in large code bases.
• Potential optimizations due to types known at compile time. If the argument and return types
of a function are given explicitly, it can be compiled into a function potentially as performant
as equivalent C code.
• Seamless interplay between typed and untyped code. You dont pay a penalty if you dont type
your code, and typed functions can be called with untyped arguments and vice versa.
1.1 The Coral Type System
When writing scientific or production code in Python, certain operations involving nested loops
or recursive function calls often become too expensive to run using pure Python. While Python
supports extensions written in a low-level language like C, these are hard to maintain and interface
poorly with Pythons object model. With Coral, these can be optimized by providing enough static
type hints for the compiler to infer all types in a given function at compile time and produce an
efficient machine code representation that can be run as fast as a lower-level language.
2