A strongly-typed language with type inference running on Erlang VM, influenced by OCaml.
OCaml
99
353 commits
updated Dec 25, 2014
A strongly-typed language with type inference running on Erlang VM, influenced by OCaml.
$ omake
make at liberl directory to compile Erlang sources used by compiled Bran modules.$ cd liberl
$ make
$ ln -s /home/yourname/bran /opt/local/bran
bin directory to command line path. (environment variable PATH, etc.)# .bashrc, etc.
export PATH=/opt/local/bran/bin:$PATH
BRAN_LIBS to the lib directory including signature files of Bran.# .bashrc, etc.
export BRAN_LIBS=/opt/local/bran/lib
liberl/ebin directory, including Erlang modules, to environment variable ERL_LIBS.# .bashrc, etc.
export ERL_LIBS=/opt/local/bran/liberl/ebin:$ERL_LIBS
bran command.$ bran
# compile
$ ./bran fib.br
# use as Erlang module
$ erl
...
1> fib:fib(10).
89
Obj module.bri (interface file).br (implementation file)([] : int list))# comment
@atom
@Atom
@atom_ok
@Atom_ok
@"atom"
@"a t o m"
@"*a+t-o/m!?* :-@"
string and char list are different types."string"
"42"
"hello, world!\n"
"\052"
"\x00\xff"
'0'
'a'
'Z'
'\n'
'\052'
'\xff'
Basically bitstring syntax is the same as one of Erlang. See Bit Syntax Expressions.
<<42>>
<<"abc">>
<<1,17,42:16>>
<<123/int-native>>
<<123/unsigned-big-integer>>
<"abc"/utf8>>
base#value is base r value (ex. 16rff). Because # is used by comment in Bran.42
042 # -> 42
2r101
16r1f
2.3
2.3e3
2.3e-3
7.000e+00
[]
[1]
[1, 2, 3]
[1, 2, 3,]
(1, "a")
[||]
[|1|]
[|1, 2, 3|]
[|1, 2, 3,|]
var x = 1
# Top level
def [rec] f x ... = [block]
# Local
def [rec] f x ... = [block] in ...
# Circular reference
def [rec] f x ... = ...
and f x ... = ...
Top level definition starts at start of line.
def f x y = x + y
In function definition, definition must be indented and end with in.
Indent size must be spaces more than one.
def f x =
def f' x' =
...
in
f' x
signature (.bri):
def f : int -> int -> int
f x y # Call function "f" with "x" and "y" arguments
f x $ g y z # => f x (g y z) Haskell's "$"
.bri:
external print_bool : bool -> unit = "bran_lib_pervasives:print_bool"
use Erlang.eval : string -> string.
var result = Erlang.eval "ok."
Conditional expression syntax is:
if [bool-exp] then [block] end
if [bool-exp] then [block] else [block] end
if [bool-exp] then [simple-exp] else [simple-exp]
"end" can be omitted when blocks have only an simple expression (literals, field access, array access, type constructor with no arguments and expression with parentheses).
Examples:
if x then
print_string "true"
true
end
if x then
print_string "true"
true
else
print_string "false"
false
end
if x then true else false
if x then true
else false
if x then
true
else
false
for i = 1 to max do
...
end
try [exp] with [pattern] end
Example:
try
...
with
| Not_found -> ...
| e -> raise e
end
perform
x1 <- action1
x2 <- action2
action3 x1 x2
return x1
end
OCaml
98.5%
A strongly-typed language with type inference running on Erlang VM, influenced by OCaml.
OCaml
99
353 commits
updated Dec 25, 2014
A strongly-typed language with type inference running on Erlang VM, influenced by OCaml.
$ omake
make at liberl directory to compile Erlang sources used by compiled Bran modules.$ cd liberl
$ make
$ ln -s /home/yourname/bran /opt/local/bran
bin directory to command line path. (environment variable PATH, etc.)# .bashrc, etc.
export PATH=/opt/local/bran/bin:$PATH
BRAN_LIBS to the lib directory including signature files of Bran.# .bashrc, etc.
export BRAN_LIBS=/opt/local/bran/lib
liberl/ebin directory, including Erlang modules, to environment variable ERL_LIBS.# .bashrc, etc.
export ERL_LIBS=/opt/local/bran/liberl/ebin:$ERL_LIBS
bran command.$ bran
# compile
$ ./bran fib.br
# use as Erlang module
$ erl
...
1> fib:fib(10).
89
Obj module.bri (interface file).br (implementation file)([] : int list))# comment
@atom
@Atom
@atom_ok
@Atom_ok
@"atom"
@"a t o m"
@"*a+t-o/m!?* :-@"
string and char list are different types."string"
"42"
"hello, world!\n"
"\052"
"\x00\xff"
'0'
'a'
'Z'
'\n'
'\052'
'\xff'
Basically bitstring syntax is the same as one of Erlang. See Bit Syntax Expressions.
<<42>>
<<"abc">>
<<1,17,42:16>>
<<123/int-native>>
<<123/unsigned-big-integer>>
<"abc"/utf8>>
base#value is base r value (ex. 16rff). Because # is used by comment in Bran.42
042 # -> 42
2r101
16r1f
2.3
2.3e3
2.3e-3
7.000e+00
[]
[1]
[1, 2, 3]
[1, 2, 3,]
(1, "a")
[||]
[|1|]
[|1, 2, 3|]
[|1, 2, 3,|]
var x = 1
# Top level
def [rec] f x ... = [block]
# Local
def [rec] f x ... = [block] in ...
# Circular reference
def [rec] f x ... = ...
and f x ... = ...
Top level definition starts at start of line.
def f x y = x + y
In function definition, definition must be indented and end with in.
Indent size must be spaces more than one.
def f x =
def f' x' =
...
in
f' x
signature (.bri):
def f : int -> int -> int
f x y # Call function "f" with "x" and "y" arguments
f x $ g y z # => f x (g y z) Haskell's "$"
.bri:
external print_bool : bool -> unit = "bran_lib_pervasives:print_bool"
use Erlang.eval : string -> string.
var result = Erlang.eval "ok."
Conditional expression syntax is:
if [bool-exp] then [block] end
if [bool-exp] then [block] else [block] end
if [bool-exp] then [simple-exp] else [simple-exp]
"end" can be omitted when blocks have only an simple expression (literals, field access, array access, type constructor with no arguments and expression with parentheses).
Examples:
if x then
print_string "true"
true
end
if x then
print_string "true"
true
else
print_string "false"
false
end
if x then true else false
if x then true
else false
if x then
true
else
false
for i = 1 to max do
...
end
try [exp] with [pattern] end
Example:
try
...
with
| Not_found -> ...
| e -> raise e
end
perform
x1 <- action1
x2 <- action2
action3 x1 x2
return x1
end
OCaml
98.5%