Stream: beginners

Topic: Can custom functions be called using dot notation?


view this post on Zulip JosephTLyons (Aug 14 2026 at 07:01):

Roc allows using . notation to call functions associated with a type / module as if they were methods. Is there any way to use . notation to call custom functions you wrote? For example, If I write a function that takes a List(a) as its first parameter, I almost want to be able to use . notation on a list instance to call that custom function. Swift has something like this called extensions, but feels like this could just happen automatically, but maybe there are drawbacks to automatically extending a types associated functions that I'm overlooking at the moment...

view this post on Zulip JosephTLyons (Aug 14 2026 at 07:04):

Example:

reduce : List(a), (a, a -> a) -> Try(a, _)
reduce = |items, operation| {
    match items {
        [] => Err(ListWasEmpty)
        [first, .. as rest] => Ok(rest.fold(first, operation))
    }
}

dbg [4, 5, 6].fold(0, U64.plus)
dbg [2, 2, 3].reduce(U64.plus) # This is an error...

view this post on Zulip Hannes (Aug 14 2026 at 07:26):

I believe Richard has said this kind of method overloading makes typechecking slower, that's part of why Swift has abysmal compile times (sorry Swift). That's all from memory, so someone else please back up/correct me :sweat_smile:

view this post on Zulip Richard Feldman (Aug 14 2026 at 11:48):

so the method overloading thing is different - that's more about "I have multiple methods with the same name and if exactly one of them happens to type-check, I want the compiler to choose that one." (The explosion is that when you combine that with type inference, the compiler has to check every possible combination of different implementations under the same name in the hopes that one of the combinations in that combinatoric explosion works.)

view this post on Zulip Richard Feldman (Aug 14 2026 at 11:49):

I think this is more like "can I add a new method to Str in userspace"

view this post on Zulip Richard Feldman (Aug 14 2026 at 11:49):

that one I don't want to allow for unrelated design reasons :smile:

view this post on Zulip Anton (Aug 14 2026 at 14:35):

Is there any way to use . notation to call custom functions you wrote?

@JosephTLyons the pizza operator is what we typically use in cases like that

view this post on Zulip JosephTLyons (Aug 14 2026 at 15:59):

Anton said:

Is there any way to use . notation to call custom functions you wrote?

JosephTLyons the pizza operator is what we typically use in cases like that

That makes sense. I'm coming from Gleam and make heavy use of the pipe operator. Totally didn't think about the fact you can just mix . calls with pipes.


Last updated: Sep 03 2026 at 15:16 UTC