Syntax Guide

Syntax for this playground is similar to that of Scala, with some simplifications and limitations. We provide a short syntax guide here.

Declarations
Item Example Notes
enum enum Food[X] {
  case Apple[Y](X, Y)
  case Banana()
}
Enum names begin with a capital letter. Enums may have 0 or more type arguments in both the type and the cases. Case arguments are unnamed.
trait trait Food[X] {
  def calories(): Int
  def foobar[Y](x: X, y: Y): Int
}
Trait names begin with a capital letter. Traits may have 0 or more type arguments in both the type and the methods.
function def toString[X](x: X): String = {
  "a string"
}
Function names begin with a lowercase letter. Function declarations may have 0 or more type arguments. Their parameter and return types must be annotated.
Expressions
Item Example Notes
constant true
123
The playground supports Boolean, integer, and string literals.
variable x
foo
arg123
Variables begin with a lower-case letter.
binary operator e + e
e > e
The playground supports arithmetic and comparison operators.
function application toString[Int](123)
print("hello")
Type parameters must be given explicitly.
pattern matching match e {
  case Food[String].Apple[Z](s, z) => e
  case Food[String].Banana() => e
}
Type parameters for the scrutinee type must be given explicitly. Case type parameters are quantified with a type variable.
enum construction Food[Int].Apple[String](123, "abc") Type parameters must be given explicitly.
method invocation obj.calories()
obj.foobar[String](1, "str")
Type parameters must be given explicitly.
object construction new Food[Bool] {
  def calories() = { 123 }
  def foobar[W](b, w) = { 456 }
}
Type parameters for the object type must be given explicitly. Method type parameters are quantified with a type variable.
if-then-else if (e) { e } else { e }
let-binding let x = 123; x + 1
sequence print("hello"); print("world")
Types
Item Example Notes
base type Int
String
Boolean
parameterized type Food[Int] Enums and traits can be parameterized with types.
type variable X
YETI
ZOETROPE
Type variables consist of all capital letters.