A small step
This small piece of Dok code is compiling and running:
data Int [
]
data A [
:^ This is the definition of `A` data type
fun f::Int {
return 0
}
variant ../B [
:^ `A/B` is a subtype (i.e. variant) of type `A`
fun f::Int -override {
: This is a normal comment, inside the code of `A/B.f`
return 1
}
]
variant ../C [
fun f::Int -override {
return 2
}
]
]
var a::A
assert a.f == 0
var b::A/B
assert b.f == 1
var c::A/C
assert c.f == 2
The syntax of Dok is rather regular, in the hope it can be also extensible with DSL. So conventions are:
- the first element is always the statement or the data declaration
[ ... ]
is used for declaring data/values{ ... }
is used for declaring instructions to run- type names are hierarchical, e.g. the type
B
has full qualified nameA/B
, and it is a subtype ofA