What does [].{} syntax mean?
I found it inside the bindings https://github.com/lukewilliamboswell/roc-platform-template-zig/blob/main/platform/Stdout.roc
Stdout := [].{
line! : Str => {}
}
Hi @gavr,
That's an excellent question, this is different from the old Roc.
:= stands for a nominal type defintion. Nominal means two types only match if they refer to the same name (and module), Stdout in this case. I think old Roc always used structural types, where two types match if they have the same underlying structure.[] is the empty tag union.{ line! : Str => {} } is the associated items block, it contains associated values/methods/types for that nominal typeFeel free to ask more questions :)
@Anton thanks, yea I just found
# Define a nominal type with a custom is_eq method
Animal := [Dog(Str), Cat(Str)].{
is_eq = |a, b| match (a, b) {
(Dog(name1), Dog(name2)) => name1 == name2
(Cat(name1), Cat(name2)) => name1 == name2
_ => Bool.False
}
}
I will create new branch with new method question, for better discoverability
By the way, here you can find the most recent version of the all syntax overview file, it no longer requires a platform: https://github.com/roc-lang/roc/blob/main/test/echo/all_syntax_test.roc
@Anton yap, already found this, my next question includes it, #beginners > How to define a static method
Last updated: Apr 10 2026 at 12:38 UTC