2. What is SCaml
Yet another compiler from OCaml to Michelson.
For Smart contracts
Strict Subset of OCaml
Small (< 3000 loc.).
and Serious
3. Strict Subset of OCaml
No fancy features for smart contracts
Many OCaml features are disabled:
No recursion
No polymoprhism
No modules
No objects
No mutability
No user defined types
4. Small
Built over OCaml’s compilerlibs.
Reusing OCaml’s parser and type-checker,
which are well tested for long time.
SCaml code only compiles OCaml’s typed AST to Michelson.
Less than 3000 lines of *.ml, written in 5 days.
5. and Serious
Serious compiler. Not a toy.
All the Michelson opcodes are supported, except
CREATE_CONTRACT.
Some optimizations in the pure ML level.
Babylon ready (i.e. entry points, closures)
6. Benefit of being Strict Subset
OCaml programmers can use SCaml without any surprise.
Newbies can learn SCaml via OCaml tutorial.
Many OCaml eco-system tools can be used for free:
Menhir, Tuareg, indender, reformatter
PPX, P4, ReasonML
etc.
7. Possibilities of being Strict Subset
Contracts can be compiled to native code with a
proper OCaml library:
Fast Monte Carlo simulations of contracts.
Contract, UI and server together in OCaml.
“Ocsigen” for Tezos:
Contracts: to Michelson by SCaml
UI: to JS by JSOO
Server: to native by OCaml
8. Compilation path
Parsing by OCaml parser
Typing by OCaml type checker
Unifying types for entry points and storage
Translation to an IL, pure monomorhpic core ML
Some inlining and partial evaluation
Compilation to Michelson
9. SCaml Features
Numeric types: int, nat, tz
Int (12), Nat 42, Tz 1.23
with monomorphic operators: (+), (+^),(+$)
Options, Lists, Sets, Maps:
Some 1, [ 1; 2; 3 ]
Set [ 1; 2; 3 ], Map [ (1, "one"), (2, "two") ]
Blockchain related constants with strings:
Key_hash "tz1..."
Pairs, Sums:
int * int, (int, int) sum
No user defined data types… yet
Aliases are OK: type 'a t = (int * ('a, nat) sum)
11. Vague Idea of Collaboration
SCaml + ReFX = SCaml + refinement type
Refinement specification as SCaml annotations.
Compiles down them to annotations in Michelson.