• This repository has been archived on 05/Feb/2018
  • Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    OCaml
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated almost 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A strongly-typed language with type inference running on Erlang VM, influenced by OCaml.

Bran

Circle CI

A strongly-typed language with type inference running on Erlang VM, influenced by OCaml.

Requirements

For usage

  • Erlang/OTP 17.3

For build

  • OCaml 4.02.1
  • Menhir 20140422
  • Spotlib 2.5.0
  • OMake 0.9.8.6-0.rc1

For test

  • OUnit2 2.0.0

Building from source

$ omake

Installation

  1. Execute make at liberl directory to compile Erlang sources used by compiled Bran modules.
$ cd liberl
$ make
  1. Copy this directory or create a symbolic link to installation destination.
$ ln -s /home/yourname/bran /opt/local/bran
  1. Add path of the bin directory to command line path. (environment variable PATH, etc.)
# .bashrc, etc.
export PATH=/opt/local/bran/bin:$PATH
  1. Set environment variable BRAN_LIBS to the lib directory including signature files of Bran.
# .bashrc, etc.
export BRAN_LIBS=/opt/local/bran/lib
  1. Add path of the liberl/ebin directory, including Erlang modules, to environment variable ERL_LIBS.
# .bashrc, etc.
export ERL_LIBS=/opt/local/bran/liberl/ebin:$ERL_LIBS
  1. OK, let's try bran command.
$ bran

Usage

# compile
$ ./bran fib.br

# use as Erlang module
$ erl
...
1> fib:fib(10).
89

ToDo

  • 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
    • Obj module
    • OTP
  • Tools
    • Interactive shell
    • Source browsing support
    • Build tool support (rebar)
  • Build
    • Installation
    • Using packaging tools (OPAM, etc.)

Syntax

Files

  • .bri (interface file)
  • .br (implementation file)

Data Types

  • unit
  • bool
  • int
  • float
  • char
  • string
  • list (empty lists must be specified type. for example: ([] : int list))
  • bitstring

Comment

# comment

Literals

Atom

@atom
@Atom
@atom_ok
@Atom_ok
@"atom"
@"a t o m"
@"*a+t-o/m!?* :-@"

String

  • On Bran, String is not a list of character type data. string and char list are different types.
  • Escape sequences are the same as one of Erlang.
"string"
"42"
"hello, world!\n"
"\052"
"\x00\xff"

Character

  • Character literals are single quote characters.
'0'
'a'
'Z'
'\n'
'\052'
'\xff'

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

  • Erlang's base#value is base r value (ex. 16rff). Because # is used by comment in Bran.
  • Integer has any number of digits.
42
042 # -> 42
2r101
16r1f

Float

2.3
2.3e3
2.3e-3
7.000e+00

List

[]
[1]
[1, 2, 3]
[1, 2, 3,]

Tuple

(1, "a")

Array

[||]
[|1|]
[|1, 2, 3|]
[|1, 2, 3,|]

Variable bindings

var x = 1

Function

Definition

# 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

Call

f x y         # Call function "f" with "x" and "y" arguments
f x $ g y z   # => f x (g y z)  Haskell's "$"

External functions

.bri:

external print_bool : bool -> unit = "bran_lib_pervasives:print_bool"

Calling Erlang functions

use Erlang.eval : string -> string.

var result = Erlang.eval "ok."

Conditional

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

Loop

for i = 1 to max do
  ...
end

Exception handling

try [exp] with [pattern] end

Example:

try
  ...
with
  | Not_found -> ...
  | e -> raise e
end

Monad

perform
  x1 <- action1
  x2 <- action2
  action3 x1 x2
  return x1
end

More Repositories

1

erlang-lz4

LZ4 bindings for Erlang
C
64
star
2

starlight

[WIP] Yet another Erlang implementation in Rust
OCaml
33
star
3

trompe

A strongly-typed handy scripting language with type inference
Go
14
star
4

omakebook-jp

A guide to OMake (written in Japanese)
Python
12
star
5

bitscan

A compact C library for operating (scanning, matching, formatting and etc.) bitstrings.
C
9
star
6

erlang-sha3

SHA3 for Erlang
C
9
star
7

esca

Esca is an experimental strongly-typed language which compiles to Go.
OCaml
8
star
8

go-clockwork-base32

A reference Implementation Clockwork-Base32 for C
Go
6
star
9

parcel

Actor-model-based concurrency library for Swift (experimental)
Swift
6
star
10

re-kanae

ReasonML base library
OCaml
5
star
11

reasonml-webapp-prototype

Sample Web application prototype in ReasonML
OCaml
4
star
12

re-siika

Sequelize.js binding for Reason
OCaml
3
star
13

strscan

string scanner in C
C
3
star
14

iori-swift

WebRTC Signaling Server Ayame in Swift
Swift
2
star
15

kiri-check

A testing library for property-based testing in Dart, enabling custom test data generation, testing stateful systems, and integrating seamlessly with package:test.
Dart
1
star
16

c-clockwork-base32

A reference Implementation of Clockwork Base32 for C
C
1
star
17

re-kaede

Base library for Reason
OCaml
1
star
18

ocalc

A RPN calculator as an example of OPAM package in OCaml
OCaml
1
star
19

swift-clockwork-base32

Reference Implementation of Clockwork Base32 for Swift
Swift
1
star
20

nini

INI file parser library for OCaml
OCaml
1
star
21

iroha

Ayame library for Flutter
Dart
1
star
22

dispatch

OCaml bindings for Apple's Grand Central Dispatch (GCD, libdispatch)
OCaml
1
star