SCaml is a strict subset of OCaml. Which features are not available?

No separate compilation

All the code for a contract must be in one .ml file.

No polymorphism

Michelson is a monomorphic language. So is SCaml.

Polymorphic value defitions are rejeted by SCaml. If your values have too general types, you make them have monomorphic types adding type constraints:

For example, the following let definition is rejected in SCaml, since its type is 'a list:

let os = [] in ...
$ scamlc
File "", line X, characters X-X:
Error: [ESCaml100] This expression has type 'a list, whose type variable 'a is not supported in SCaml.

You have to add a type constraint to restrict the type variable:

let os : operation list = [] in ...

No recursion

Michelson does not have an opcode for recursion. Therefore SCaml does not support recursive definitions either: let rec bindings are rejected.

Still there are still some recursions are available:

  • Module SCaml provides mappings and foldings of list, set, map, and big maps, such as, SCaml.Set.fold, etc.
  • Module SCaml also provides a simple looping: Loop.left.

It might be possible to encode recursion in SCaml using Michelson's closure creation and serializers (Obj.pack and Obj.unpack), but it should be very gas inefficient. Do it at your own risk.

No recursive type definitions

SCaml does not support user defined recursive types, because neither does Michelson.

type t = ... can define variants (sums) and records but they must be non recursive.

Primitive types have some recursion: list, set, map, and big_map.

No modules

Modules, functors, and first class modules are not supported.

No labeled functions

Labeled functions and optional arguments are not supported.

No partial applicatons of primitives

Primitives defined in module SCaml must be applied fully.

No side effects

No reference, mutable record fields, arrays. No I/O.

No exceptions

SCaml.failwith and SCaml.assert fail contract executions immediately. There is no way to catch these failures.

No polymorphic variants

Types of polymorphic variants often contain generalized type variables, which make them hard to use in SCaml, a monomorphic language: type constraints should be required everywhere around them.

You can use the normal variants without complications.

No classes nor objects

Object oriented features are not supported. SCaml is not SOCaml nor OSCaml.

Last modified March 6, 2020: update (fc2311b)