NOTE: This manual is a work in progress. Please let us know if you think something is missing by filing an issue, or join our Discord server.

Syntax Cheatsheet

Here is a comparison between common Erlang and Elixir syntaxes and the OCaml and Reason syntaxes that are supported by Caramel.

Types

Variants and Unions

Erlang:

-type bool() :: true | false.
-type foo() :: bar() | baz().

Elixir

@type bool() :: true | false
@type foo() :: bar() | baz()

OCaml

type bool = True | False
type foo = Bar of bar | Baz of baz
type foo = [ `Bar of bar | `Baz of baz ]
type foo = [ bar | baz ] (* for when bar and baz are polymorphic variants *)

Records

Erlang:

-type pair(A, B) :: #{ fst => A, snd => B }.

Elixir

@type pair(a, b) :: %{ :fst => a(), :snd => b() }

OCaml

type ('a, 'b) pair = { fst : 'a; snd : 'b }

Expressions and Values

Atoms

ErlangElixirOCamlReasonDescription
ok:ok`ok`okAtoms in Caramel are treated as polymorphic variants.
'ok':'ok'------Quoted atoms are unsupported in Caramel.

Comments

ErlangElixirOCamlReason
% comment# comment(* comment *)// comment

Variables

ErlangElixirOCamlReason
A = 1a = 1let a = 1let a = 1
A2 = A + 1a = 1let a' = a + 1let a' = a + 1

Binary Strings, and Charlists

ErlangElixirOCamlReason
<<"binary">>"binary""binary""binary"
"string"'binary'['b'; 'i'; 'n'; 'a'; 'r'; 'y']['b', 'i', 'n', 'a', 'r', 'y']

Function Calls

ErlangElixirOCamlReason
Lambda()lambda.()lambda ()lambda()
local()local()local ()local()
mod:fn()Mod.fn()Mod.fn ()Mod.fn()
A:F()apply(A, F, [])------

Dynamically dispatched calles are not supported in Caramel, because we can't know the type of the arguments they will have, or the type of the value they would return.

If expressions

Erlang:

if 
  Foo -> Bar;
  _ -> Baz
end.

Elixir

if(foo, do: bar, else: baz)

if foo do
  bar
else 
  baz
end

OCaml

if foo then bar else baz

Reason

foo ? bar : baz

Match / Case / Switch expression

Erlang:

case Foo of
  Bar -> Baz
end.

Elixir

case foo do
  bar -> baz
end

OCaml

match foo with
| bar -> baz

Reason

switch foo {
| bar => baz
}