Stream: beginners

Topic: Alias for destructured record


view this post on Zulip Ilya Shmygol (Apr 23 2025 at 16:43):

Isn't it possible to do {a, b} as full_record in the function arguments as is it is in when-is?

view this post on Zulip Ilya Shmygol (Apr 23 2025 at 16:44):

This definition fails:

add_user : Database, { name : Str, owes ?? Dict Str Dec, owed_by ?? Dict Str Dec, balance ?? Dec} -> Result Database _
add_user = |database, { name, owes ?? Dict.empty({}), owed_by ?? Dict.empty({}), balance ?? 0.0} as user|

with error:

── MALFORMED ARGS LIST in ./Database.roc ───────────────────────────────────────

I was trying to parse the arguments list for a function, but I got
stuck here:

19│  add_user = |database, { name, owes ?? Dict.empty({}), owed_by ?? Dict.empty({}), balance ?? 0.0} as user|
                                                                                                      ^

I was expecting to find a | next.%

view this post on Zulip Anton (Apr 23 2025 at 17:14):

Not yet supported, but seems reasonable to add. Do you expect any problems from this @Anthony Bullard, @Joshua Warner?

view this post on Zulip Sam Mohr (Apr 23 2025 at 21:12):

That should be fine so long as the left side of the x as y is an exhaustive pattern. I believe this has been already implemented in the way that @Ilya Shmygol wrote it in the new compiler's parsing code, but I might be wrong

view this post on Zulip Brendan Hansknecht (Apr 23 2025 at 22:31):

Yeah, I think it just doesn't work with ??

view this post on Zulip Brendan Hansknecht (Apr 23 2025 at 22:31):

But not fully sure

view this post on Zulip Anthony Bullard (Apr 24 2025 at 00:55):

I honestly can’t remember if this will in fact “just work” in the new parser but I think so. I wish I had time to look at it right now

view this post on Zulip Sam Mohr (Apr 24 2025 at 02:44):

Brendan is probably right, but for those who don't know, ?? is going away in the rewrite

view this post on Zulip Anthony Bullard (Apr 24 2025 at 02:46):

That’s news to me and the parser :joy:

view this post on Zulip Richard Feldman (Apr 24 2025 at 03:13):

wait, me too! :laughing:

view this post on Zulip Richard Feldman (Apr 24 2025 at 03:13):

unless I'm misremembering?

view this post on Zulip Brendan Hansknecht (Apr 24 2025 at 05:24):

Optional/default value record fields are going away

view this post on Zulip Brendan Hansknecht (Apr 24 2025 at 05:24):

I think ?? is switching to be Result.with_default(...)

view this post on Zulip Brendan Hansknecht (Apr 24 2025 at 05:25):

At least that is what I remember being decided

view this post on Zulip Brendan Hansknecht (Apr 24 2025 at 05:25):

But not fully sure on with default.

view this post on Zulip Anthony Bullard (Apr 24 2025 at 10:35):

That’s somewhat sad, since it was implemented not even six months ago (by me) and has just as much value in a static dispatch world as before. And with_default has been there and will remain for when you want to chain it (we almost had ?? Desugar to it, but chose to use a when instead)

view this post on Zulip Ilya Shmygol (Apr 24 2025 at 10:41):

I liked ??...

view this post on Zulip Richard Feldman (Apr 24 2025 at 12:55):

yeah I don't remember that change haha

view this post on Zulip Richard Feldman (Apr 24 2025 at 12:55):

in my mind, the plan was still to have ?? work the same as today

view this post on Zulip Richard Feldman (Apr 24 2025 at 12:56):

can anyone find a thread where we discussed changing that?

view this post on Zulip Anthony Bullard (Apr 24 2025 at 13:44):

It may have stemmed from this discussion?

Brendan Hansknecht said:

Now that we have static dispatch do we expect to see issues with ? and ?? ?
They no longer play nice with pipelines

out =
    (((load_config(in_file) ?? default_config)
        .stage1(abc) ? Stage1Err)
        .stage2() ? Stage2Err)
        .stage3() ? Stage3Err

view this post on Zulip Brendan Hansknecht (Apr 24 2025 at 15:52):

To clarify my statement. In the new compiler, I would expect this to still just work:

out =
    (((load_config(in_file) ?? default_config)
        .stage1(abc) ? Stage1Err)
        .stage2() ? Stage2Err)
        .stage3() ? Stage3Err

view this post on Zulip Brendan Hansknecht (Apr 24 2025 at 15:55):

I just recall a discussion on default value record fields like:

fn = |record : {x ?? i32, y ?? i32}|
    {x ?? 0, y ?? 0} = record
    x + y

In that discussion, richard suggested we should remove them cause overall they had been confusing and error prone for users.

view this post on Zulip Brendan Hansknecht (Apr 24 2025 at 16:13):

I think this is the most official message of removal, but significant discussion definitely happened in idea threads much earlier:
Richard Feldman said:

of note, the "demanded" enum for records isn't necessary anymore due to optional record fields going away

view this post on Zulip Richard Feldman (Apr 24 2025 at 16:52):

ohh yeah, I misunderstood

view this post on Zulip Richard Feldman (Apr 24 2025 at 16:52):

so my understanding is that:

view this post on Zulip Brendan Hansknecht (Apr 24 2025 at 16:59):

:nod-yes: yeah, exactly that.

view this post on Zulip Sam Mohr (Apr 25 2025 at 00:23):

yep!

view this post on Zulip Anthony Bullard (Apr 25 2025 at 13:00):

Sweet, that makes sense


Last updated: Jul 06 2025 at 12:14 UTC