Stream: ideas

Topic: static dispatch - tuple accessors and zero-arg functions


view this post on Zulip Richard Feldman (Jan 13 2025 at 04:20):

random idea that static dispatch enables (not saying we should or shouldn't do this, just an idea):

view this post on Zulip Richard Feldman (Jan 13 2025 at 04:27):

separately (also not saying this part is or isn't a good idea either), that would mean that if we wanted to, we could do the ".( means partial application" idea from #ideas > static dispatch - partial application syntax by having "partially applied function" be a valid type (since that requires having a first-class concept of 0-arg functions)

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:27):

If this means I can stop working on fixing mono bugs with (), I'm here for it /s

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:28):

I really think having zero-arg functions is a must-have for Roc

view this post on Zulip Richard Feldman (Jan 13 2025 at 04:28):

it definitely is the most obvious design

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:28):

And parens make a lot of sense for notating functions

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:28):

Tuples aren't that important in the scheme of things

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:29):

So if we can make them usable in some other way such that parens can handle arg notation, then Roc looks more consistent and we don't have to use 3 different kinds of syntax sugar as a stopgap

view this post on Zulip Richard Feldman (Jan 13 2025 at 04:29):

well as discussed in #ideas > ✔ Do we need tuples? they're important enough to be worth having in the language, and it's frequently annoying if the only way to get values out of them is to destructure them :sweat_smile:

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:29):

I'm all in on this

view this post on Zulip Richard Feldman (Jan 13 2025 at 04:29):

but yeah, static dispatch means we can simplify them I think

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:29):

Yes, we need them

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:30):

I really like the idea of types and values looking more similar

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:32):

get_results! : () => Result(List(U64), LoadErr)
read_file! = ||
    res = load_results!()?
    Ok(res.transform())

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:32):

That's not explicitly proposed here

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:33):

Though this moves us in that direction

view this post on Zulip Richard Feldman (Jan 13 2025 at 04:33):

ah, I think someone brought that up at some point

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:34):

Yep, let me find the thread

view this post on Zulip Richard Feldman (Jan 13 2025 at 04:34):

I don't have strong feelings about it (both ways look fine to me), but feel free to start an #ideas thread on it!

view this post on Zulip Richard Feldman (Jan 13 2025 at 04:36):

I know List<U64> is the most mainstream, but I do think that looks significantly worse than either (List U64) or List(U64), especially once you end up in >>> territory

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:36):

Yep, I'd be pushing for List(U64)

view this post on Zulip Richard Feldman (Jan 13 2025 at 04:36):

Scala uses List[U64] as I recall, but we already use [ ] for something else

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:36):

That's how tags work now anyways

view this post on Zulip Richard Feldman (Jan 13 2025 at 04:36):

looks like Gleam uses List(U64)

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:36):

So it's just an extension of that

view this post on Zulip Richard Feldman (Jan 13 2025 at 04:37):

so maybe we could see how Gleam folks feel about it in practice? I don't know of any other languages which use that syntax

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:37):

They have a Discord, or we could ask here?

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:37):

I'll start that thread, anyhow

view this post on Zulip Richard Feldman (Jan 13 2025 at 04:38):

good to get these things sorted out one way or the other prior to 0.1.0 :big_smile:

view this post on Zulip Sam Mohr (Jan 13 2025 at 04:39):

Yep, I guess Syntax Season just got Punxsutawney Phil'ed!

view this post on Zulip Richard Feldman (Jan 13 2025 at 04:39):

there's no :groundhog: so I guess :hedgehog: will have to do

view this post on Zulip Brendan Hansknecht (Jan 13 2025 at 04:43):

This sounds reasonable. I honestly feel like tuples are less important than originally proposed:

  1. They don't solve the lack of arrays. It is still nicer to use a list than a tuple most of the time. Still can be a win for like a Vec3 type, but isn't a win for a Matrix type. (And you can't use them to make any sort of generic or flexible matrix)
  2. They easily can be replaced with records and probably should be in a number of cases.

I still think they are pretty fundamental for returning multiple things and certain cases where records are too verbose, but otherwise, I feel like they don't add value to the language.

view this post on Zulip Richard Feldman (Jan 13 2025 at 05:37):

another neat thing: we could automatically give tuples .map_0() and .map_1() as well - I've used things like Tuple.mapFirst in Elm before

view this post on Zulip Anthony Bullard (Jan 13 2025 at 14:22):

Just a question since there is renewed scrutiny around SD (and we don't know how it will go eventually anyway), but regardless of what happens - it still makes sense for a language with effectual functions to allow effectual functions to have zero args - and therefore a way to annotate that, correct?

view this post on Zulip Richard Feldman (Jan 13 2025 at 14:38):

I agree, yeah

view this post on Zulip Oskar Hahn (Jan 15 2025 at 07:50):

Have you talked about allowing multiple return values? If the main reason for tuples is returning multiple values, then maybe supporting it directly is even better.

I really hate, that zig does not support multiple return values. Multiple return values is an important feature to support webassembly. There are things, in the webassembly world, that zig does not support because of this. They have an issue where there discuss to support it.

I don't think that the c-abi is a problem. This could only be a problem for functions provided by the platform to the host or effects defined by the platform. App code does not have to support c-abi. A platform knows, which abi it wants to support. If a platform wants to return multiple values to the host with c-abi, it can do it in a record, which has (nearly) the same memory layout then tuples. (Records order the fields, so it would not be possible to create a type like (U8, U64) .)

I don't say, that tuples should be removed from Roc. I want to say, that multiple return values is not a strong argument to keep them. I made the experience, that records are superior to tuples and the only reason I use tuples is because I am lazy.

view this post on Zulip Sam Mohr (Jan 15 2025 at 07:53):

From Richard's recent thread in #ideas > Result.map_ok, here are two code examples showing the difference between tuples and records:

without tuples

params : Request -> List (Str, Str)
params = |req|
    req
    .path()
    .split_first("?")
    .map_ok(.after)
    .with_default("")
    .split_on("&")
    .map(|param|
        when param.split_first("=") is
            Ok({ before, after }) -> (before, after)
            Err(NotFound) -> (param, "")
    )

with tuples

params : Request -> List (Str, Str)
params = |req|
    req
    .path()
    .split_first("?")
    .map_ok(.get_1())
    .with_default("")
    .split_on("&")
    .map(|param| param.split_first("=") ?? (param, ""))

For those APIs where the output values are made obvious by the function name and return type, tuples are less noisy.

view this post on Zulip Sam Mohr (Jan 15 2025 at 07:55):

So as you probably agree, something like tuples should probably remain in Roc, though I'm with you that records are always more descriptive

view this post on Zulip Sam Mohr (Jan 15 2025 at 07:55):

But I think you're right that we should consider allowing multiple return values in place of tuples, even after all the discussion we've had on the subject

view this post on Zulip Sam Mohr (Jan 15 2025 at 07:56):

Tuples seem good for:

view this post on Zulip Sam Mohr (Jan 15 2025 at 07:58):

I think if we supported arrays in Roc, then all of a sudden tuples are much closer to a full type system feature that could instead be a syntax nicety

view this post on Zulip Sam Mohr (Jan 15 2025 at 07:59):

However, I don't know how to support something like

when (left, right) is
    (Blue, Green) -> ...

without adding lots of little tools that the singular addition of tuples doesn't handle

view this post on Zulip Brendan Hansknecht (Jan 15 2025 at 22:08):

Sam Mohr said:

Tuples seem good for:

This almost never happens in practice. I think it is too niche/unergonomic to really be consider a benefit.

I do totally agree they are awesome for multiple return values and pattern matching.


Last updated: Jun 16 2026 at 16:19 UTC