Modules
Modules, inspired from OCaml, provide a way to organize and manage large code bases. They enable the creation of interfaces between separate parts of the code base, and can reduce noise by reconciling different instances of operators with implicits.
Creation
Modules are created with mod .. end
. Definitions are like let
-expressions, but bind to the module instead of a scope. Modules are expressions, like any other.
mod
def z = 0
def s x = x + 1
end
==> (A module)
Let's us a let expression to bind the module to a name.
let m = mod
def z = 0
def s x = x + 1
end ->
Access
Modules can have their fields accessed using .
(dot). Dot has faster precedence than concatenation. Let's use the same m
from before.
m.z m.s m.s
==> 2
Open
Instead of using access, we can open a module, putting its contents in scope, by matching it against open
.
m as open ->
z s{5}
==> 5
More to come!