I've only just started reading the Roc documentation and it seems like a really humane and well thought out language--great work!
I was wondering if this syntax ...}.{... as used in the following code can be split into separate declarations or sections. It's probably just me but I find the "." character is doing a lot of conceptual work in linking the {} sections.
Apologies if this is answered in the docs I haven't gotten to yet.
Builder(a) := { value : a }.{
pure : a -> Builder(a)
pure = |x| { value: x }
map2 : Builder(a), Builder(b), (a, b -> c) -> Builder(c)
map2 = |a, b, combine| { value: combine(a.value, b.value) }
run : Builder(a) -> a
run = |builder| builder.value
}
record_builder = || {
built = {
count: Builder.pure(42.U64),
name: Builder.pure("Roc"),
}.Builder
# The two-field builder above calls Builder.map2 with a function that makes the record.
built.run()
}
I don't think this question has ever come up before. I've not seen anything about it.
I'm guessing that syntax } . { might be special to define a block for associated things on a type
I'm not sure if it's possible to split into another line.. what might that look like?
In the meantime I'll keep reading. Nice to see someone in my timezone too (UTC+11)
:flag_australia: :rock_on:
RN no.
I think trying to do
A := {fields}.{funcs}
A.{new funcs}
Is not going to work.
You can put private helpers out side this class def, but yeah that's not really what you ask for.
Technically you can do
A := {}
.{}
But fmt will immediately put them back and nuke the \n.
What is the conceptual work you are thinking about here... is it just an unfamiliar feeling maybe?
Thanks for the quick reply, much appreciated.
Also ... what do you think of the record builder pattern :grinning_face_with_smiling_eyes:
I've been using it a fair bit, though it's fairly new still. Here's an example in roc-signals
My first impression was that the first {} block is one concept/thing/idea and the second {} is a related but different concept/thing/idea and the two are linked by a single character rather than a statement or expression of some kind. I suspect as I keep reading the reason for this will become more and more sensible.
Part of that design comes from Zig where it is idiomatic to nest types within each other
The record builder approach looks neat. There are so many good ideas here (e.g. platforms)
TBF there is some point here, a naive combination of A.{funcs} shouldnt cause big issue in terms of compiling & optimizing.
But that feature probably(?) won't be added in 0.1.x.
I've experimented with Rust, Gleam, Elixir, Haskell, Mojo et al but somehow missed Zig.
The syntax has evolved very organically over the years, many experiments and redesigns. This 0.1 variation hasn't really changed much at all in a while, it's been sitting really nicely
Thought I'm not sure organically and experiments go together like that
It's been a long journey with many people trying things out
re: the original question, when hand-writing Roc, I like to throw a comma after the fields so the formatter does this:
Builder(a) := {
value : a,
}.{
pure : a -> Builder(a)
pure = |x| { value: x }
Last updated: Nov 26 2026 at 20:35 UTC