szktty/bran
A strongly-typed language with type inference running on Erlang VM, influenced by OCaml.
{ "createdAt": "2014-11-16T12:32:21Z", "defaultBranch": "develop", "description": "A strongly-typed language with type inference running on Erlang VM, influenced by OCaml.", "fullName": "szktty/bran", "homepage": null, "language": "OCaml", "name": "bran", "pushedAt": "2014-12-25T15:53:15Z", "stargazersCount": 100, "topics": [], "updatedAt": "2024-11-05T00:45:11Z", "url": "https://github.com/szktty/bran"}A strongly-typed language with type inference running on Erlang VM, influenced by OCaml.
Requirements
Section titled “Requirements”For usage
Section titled “For usage”- Erlang/OTP 17.3
For build
Section titled “For build”- OCaml 4.02.1
- Menhir 20140422
- Spotlib 2.5.0
- OMake 0.9.8.6-0.rc1
For test
Section titled “For test”- OUnit2 2.0.0
Building from source
Section titled “Building from source”$ omakeInstallation
Section titled “Installation”- Execute
makeatliberldirectory to compile Erlang sources used by compiled Bran modules.
$ cd liberl$ make- Copy this directory or create a symbolic link to installation destination.
$ ln -s /home/yourname/bran /opt/local/bran- Add path of the
bindirectory to command line path. (environment variablePATH, etc.)
# .bashrc, etc.export PATH=/opt/local/bran/bin:$PATH- Set environment variable
BRAN_LIBSto thelibdirectory including signature files of Bran.
# .bashrc, etc.export BRAN_LIBS=/opt/local/bran/lib- Add path of the
liberl/ebindirectory, including Erlang modules, to environment variableERL_LIBS.
# .bashrc, etc.export ERL_LIBS=/opt/local/bran/liberl/ebin:$ERL_LIBS- OK, let’s try
brancommand.
$ bran# compile$ ./bran fib.br
# use as Erlang module$ erl...1> fib:fib(10).89- Data types
- Map
- Option
- Reference
- Exception
- Binary
- Process
- Type system
- Records
- Variants
- Polymorphic type
- Syntax
- Pattern matching
- Exception handling
- Labeled arguments and optional arguments
- Message passing
- Compilation
- Optimization
- Executable file generation (escript)
- Library
- Standard library
Objmodule- OTP
- Tools
- Interactive shell
- Source browsing support
- Build tool support (rebar)
- Build
- Installation
- Using packaging tools (OPAM, etc.)
Syntax
Section titled “Syntax”.bri(interface file).br(implementation file)
Data Types
Section titled “Data Types”- unit
- bool
- int
- float
- char
- string
- list (empty lists must be specified type. for example:
([] : int list)) - bitstring
Comment
Section titled “Comment”# commentLiterals
Section titled “Literals”@atom@Atom@atom_ok@Atom_ok@"atom"@"a t o m"@"*a+t-o/m!?* :-@"String
Section titled “String”- On Bran, String is not a list of character type data.
stringandchar listare different types. - Escape sequences are the same as one of Erlang.
"string""42""hello, world!\n""\052""\x00\xff"Character
Section titled “Character”- Character literals are single quote characters.
'0''a''Z''\n''\052''\xff'Bitstring
Section titled “Bitstring”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>>Integer
Section titled “Integer”- Erlang’s
base#valueisbase r value(ex. 16rff). Because#is used by comment in Bran. - Integer has any number of digits.
42042 # -> 422r10116r1f2.32.3e32.3e-37.000e+00[][1][1, 2, 3][1, 2, 3,](1, "a")[||][|1|][|1, 2, 3|][|1, 2, 3,|]Variable bindings
Section titled “Variable bindings”var x = 1Function
Section titled “Function”Definition
Section titled “Definition”# Top leveldef [rec] f x ... = [block]
# Localdef [rec] f x ... = [block] in ...
# Circular referencedef [rec] f x ... = ...and f x ... = ...Top level definition starts at start of line.
def f x y = x + yIn 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' xsignature (.bri):
def f : int -> int -> intf x y # Call function "f" with "x" and "y" argumentsf x $ g y z # => f x (g y z) Haskell's "$"External functions
Section titled “External functions”.bri:
external print_bool : bool -> unit = "bran_lib_pervasives:print_bool"Calling Erlang functions
Section titled “Calling Erlang functions”use Erlang.eval : string -> string.
var result = Erlang.eval "ok."Conditional
Section titled “Conditional”Conditional expression syntax is:
if [bool-exp] then [block] endif [bool-exp] then [block] else [block] endif [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" trueend
if x then print_string "true" trueelse print_string "false" falseend
if x then true else false
if x then trueelse false
if x then trueelse falsefor i = 1 to max do ...endException handling
Section titled “Exception handling”try [exp] with [pattern] endExample:
try ...with | Not_found -> ... | e -> raise eendperform x1 <- action1 x2 <- action2 action3 x1 x2 return x1end