Hello world
Every Elara program starts with amain function of type IO ():
Identifiers
Elara uses case-sensitive identifiers with specific naming conventions:- Variables and functions: Start with a lowercase letter (e.g.,
myFunction,x,calculate) - Types and constructors: Start with an uppercase letter (e.g.,
Int,String,Some,None) - Modules: Use
UpperCamelCaseseparated by dots (e.g.,Main,Foo.Bar)
Comments
Elara supports single-line comments using--:
Declarations
Functions are declared withdef for type signatures and let for implementations:
The
def keyword declares the type signature, while let provides the implementation. Both are required for top-level functions.Literals
Elara supports several literal types:Numbers
Strings
Characters
Booleans
Lists
Tuples
Lightweight syntax
Elara supports lightweight syntax, where semicolons and braces are optional and inferred from indentation.- Lightweight syntax (recommended)
- Normal syntax
Offside rule
When using lightweight syntax, indentation is significant. Code at the same indentation level is part of the same block:Operators
Elara supports infix operators with customizable precedence:Function application
Function application uses juxtaposition (no parentheses needed):Parentheses are only needed to group expressions or clarify precedence.
add 2 3 applies add to 2 and then to 3.Lambda expressions
Anonymous functions use the\ (backslash) syntax:
Let bindings
Local variables are declared withlet ... in ... expressions: