Stream: beginners

Topic: Splitting `...}.{...` syntax?


view this post on Zulip Stuart Hungerford (Nov 22 2026 at 03:23):

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()
}

view this post on Zulip Luke Boswell (Nov 22 2026 at 03:35):

I don't think this question has ever come up before. I've not seen anything about it.

view this post on Zulip Luke Boswell (Nov 22 2026 at 03:36):

I'm guessing that syntax } . { might be special to define a block for associated things on a type

view this post on Zulip Luke Boswell (Nov 22 2026 at 03:36):

I'm not sure if it's possible to split into another line.. what might that look like?

view this post on Zulip Stuart Hungerford (Nov 22 2026 at 03:40):

In the meantime I'll keep reading. Nice to see someone in my timezone too (UTC+11)

view this post on Zulip Luke Boswell (Nov 22 2026 at 03:41):

:flag_australia: :rock_on:

view this post on Zulip zhen (Nov 22 2026 at 03:46):

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.

view this post on Zulip Luke Boswell (Nov 22 2026 at 03:48):

What is the conceptual work you are thinking about here... is it just an unfamiliar feeling maybe?

view this post on Zulip Stuart Hungerford (Nov 22 2026 at 03:48):

Thanks for the quick reply, much appreciated.

view this post on Zulip Luke Boswell (Nov 22 2026 at 03:49):

Also ... what do you think of the record builder pattern :grinning_face_with_smiling_eyes:

view this post on Zulip Luke Boswell (Nov 22 2026 at 03:50):

I've been using it a fair bit, though it's fairly new still. Here's an example in roc-signals

https://github.com/lukewilliamboswell/roc-signals/blob/e23f5c6992e47c49c301e05c6c23060e0b5dcdf4/examples/kanban-board/AppStore.roc#L30-L39

view this post on Zulip Stuart Hungerford (Nov 22 2026 at 03:51):

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.

view this post on Zulip Luke Boswell (Nov 22 2026 at 03:52):

Part of that design comes from Zig where it is idiomatic to nest types within each other

view this post on Zulip Stuart Hungerford (Nov 22 2026 at 03:52):

The record builder approach looks neat. There are so many good ideas here (e.g. platforms)

view this post on Zulip zhen (Nov 22 2026 at 03:55):

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.

view this post on Zulip Stuart Hungerford (Nov 22 2026 at 03:56):

I've experimented with Rust, Gleam, Elixir, Haskell, Mojo et al but somehow missed Zig.

view this post on Zulip Luke Boswell (Nov 22 2026 at 03:59):

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

view this post on Zulip Luke Boswell (Nov 22 2026 at 03:59):

Thought I'm not sure organically and experiments go together like that

view this post on Zulip Luke Boswell (Nov 22 2026 at 04:00):

It's been a long journey with many people trying things out

view this post on Zulip Dan G Knutson (Nov 22 2026 at 15:51):

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