██████╗ █████╗ ██████╗ ███████╗██╗ ██╔══██╗██╔══██╗██╔════╝ ██╔════╝██║ ██████╔╝███████║██║ ███╗█████╗ ██║ ██╔══██╗██╔══██║██║ ██║██╔══╝ ██║ ██████╔╝██║ ██║╚██████╔╝███████╗███████╗ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚══════╝ ︵‿︵‿୨♡୧‿︵‿︵ better syntax ocaml (subjectively)
Ocaml syntax is... weird. Let's use a better syntax !
let x: int = 1;;
let y = 5;;
to
int x = 1;
// Type Inference: reducing the need for explicit type declarations
auto y = 5;
let add (a, b : int * int) {
a + b
};;
let main () : unit = (
...
);;
to
int add(int a, int b) {
return a + b;
}
unit main() {
...
}
let x: int ref = ref 0;;
!x;;
x := 1;
to
int* x = &0;
x.get();
x.set(1);
let find_value (key : int) : int option;;
let divide (numerator, denominator : int * int) : (int, error) result;;
to
Option<int> find_value(int key);
Result<int, Error> divide(int numerator, int denominator);
// Namespaces & class definitions that resemble C++
namespace Math {
int add(int a, int b) {
return a + b;
}
}
class Point {
public:
int x;
int y;
Point(int x, int y) {
this->x = x;
this->y = y;
}
void move(int dx, int dy) {
x += dx;
y += dy;
}
}
// Recursive functions
#[recursive, debug]
int fibo(int n) {
if (n <= 1) {
return n;
}
return fibo(n - 1) + fibo(n - 2);
}
// Anonymous functions
auto inc = [](int x) {
return x + 1;
};
// Maps
auto squares = map([1, 2, 3], [](int x) { return x * 2; });
While loops are faster than for, local and blocks loops