Strings
```reasonligo
let name: string = "Tezos"
```
Characters
```reasonligo
let t: string = "t"
```
Integers
```reasonligo
let i: int = 42
```
Natural numbers
```reasonligo
let n: nat = 7n
```
Unit
```reasonligo
let u: unit = unit
```
Boolean
```reasonligo
let has_drivers_license: bool = false
let adult: bool = true
```
Boolean Logic
```reasonligo
let booleanLogic: bool =
(!true) ==
false ==
(false && true) ==
(false || false)
```
Mutez (micro tez)
```reasonligo
let tez: tez = 42tez
let tez: tez = 7mutez
```
Address
```reasonligo
let tz1address: address =
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)
let kt1address: address =
("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address)
```
Addition
```reasonligo
let add_int: int = 3 + 4
let add_nat: nat = 3n + 4n
```
Multiplication & Division
```reasonligo
let mul_int: int = 3 + 4
let mul_nat: nat = 3n + 4n
let div_int: int = 10 / 5
let div_nat: nat = 10n / 5n
```
Modulo
```reasonligo
let mod_nat: nat = 10 mod 3
```
Tuples
```reasonligo
type name = (string, string)
let winner: name = ("John", "Doe")
let firstName: string = winner[0]
let lastName: string = winner[1]
```
Types
```reasonligo
type age = int
type name = string
```
Includes
```#include "library.religo"```
Functions (short form)
```reasonligo
let add = (a: int, b: int): int =>
a + b
```
Functions (long form)
```reasonligo
let add = (a: int, b: int): int => {
let c = a;
let d = b;
c + d
};
```
If Statement
```reasonligo
let if_statement = (age : int) : int =>
if (age < 16) {
(failwith ("Too young to drive"): int)
} else {
1
}
```
Options
```reasonligo
type middle_name = option(string);
let middle_name : middle_name = Some ("Foo");
let middle_name : middle_name = None;
```
Variable Binding
```reasonligo
let age: int = 5
```
Type Annotations
```reasonligo
let someAddress: address =
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)
```
Variants
```reasonligo group=variants
type action =
| Increment (int)
| Decrement (int)
```
Variant *(pattern)* matching
```reasonligo group=variants
let a: action = Increment(5)
let result: int = switch (a) {
| Increment(n) => n + 1
| Decrement(n) => n - 1
}
```
Records
```reasonligo
type person = {
age: int,
name: string
}
let john : person = {
age: 18,
name: "john doe"
}
let name: string = john.name
```
Maps
```reasonligo
type prices = map (nat, tez)
let prices: prices = Map.literal ([
(10n, 60mutez),
(50n, 30mutez),
(100n, 10mutez),
])
let price: option(tez) = Map.find_opt(50n, prices)
let prices : prices = Map.update(200n, (Some 5mutez), prices)
```
Contracts & Accounts
```reasonligo group=tezos_specific
let destinationAddress: address =
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)
let contract : contract(unit) =
switch (Tezos.get_contract_opt(Tezos.sender) : option(contract(unit))) {
| Some(contract) => contract
| None => (failwith("no contract") : contract(unit))
}
```
Transactions
```reasonligo group=tezos_specific
let payment: operation =
Tezos.transaction(unit, 100mutez, contract);
```
Exception/Failure
```reasonligo
let fail = (u: unit) : unit =>
failwith("a failure message")
```