Skip to main content

Objects

An object declares a type and its one instance together. There's nothing to construct: the object exists, and its name is how you use it:

object Settings {
let volume = 7

let describe() = "volume ${volume}"
}

entrypoint main() {
println(Settings.describe())
}

Use an object for something there is only ever one of, such as a program's settings or a set of helper functions.

Implementing a trait​

An object can implement a trait, so it can stand wherever that trait is expected:

trait Greeter {
let greet() : string
}

object Polite : Greeter {
override let greet() = "Good morning"
}