Stream: beginners

Topic: Task.attempt vs Task.result


view this post on Zulip Kilian Vounckx (Jun 20 2024 at 15:41):

With the new ! syntax, what would be the recommended way to convert from a task to a result?

result <- Task.attempt task
useResult result

or

result = Task.result! task
useResult result

I assume the new way is going to be more idiomatic. Are there any differences, both functionally as performance?

view this post on Zulip Mythmon (Jun 20 2024 at 16:34):

I'm very new to Roc myself, but yesterday I was told that usage of the left arrow <- is probably going to be removed from the language. So your second example is probably the preferred syntax

view this post on Zulip Brendan Hansknecht (Jun 20 2024 at 19:41):

Yep, second example is preferred

view this post on Zulip Kilian Vounckx (Jun 20 2024 at 20:20):

I didn't now <- was going to be removed completely. Does this mean we won't be able to (ab)use it anymore with functions like List.map?

view this post on Zulip Brendan Hansknecht (Jun 20 2024 at 20:48):

It's really bittersweet to me... But assuming ! goes well and uses of <- are pretty low, the plan is to eventually fully remove it.

view this post on Zulip Brendan Hansknecht (Jun 20 2024 at 20:48):

Personally, I like <- for generators and results.

view this post on Zulip Kilian Vounckx (Jun 20 2024 at 20:49):

Yeah, I use it for result a lot too. But the extended ! syntax could cover that

view this post on Zulip Brendan Hansknecht (Jun 20 2024 at 20:49):

But I understand that ! causes a ton of confusion for new users and turns people away from the language so we want to remove it if possible. Personally, I wish I could define ! on any opaque type. That would make me happy.

view this post on Zulip Brendan Hansknecht (Jun 20 2024 at 20:50):

But the extended ! syntax could cover that

We just need to record enough friction/demand that it actually gets added. Our default is to wait on adding that type of stuff. Makes sure it has clear value.

view this post on Zulip Kilian Vounckx (Jun 20 2024 at 20:51):

Brendan Hansknecht said:

Personally, I wish I could define ! on any opaque type. That would make me happy.

That would become something like a Monad ability then?

view this post on Zulip Kilian Vounckx (Jun 20 2024 at 20:51):

Brendan Hansknecht said:

But the extended ! syntax could cover that

We just need to record enough friction/demand that it actually gets added. Our default is to wait on adding that type of stuff. Makes sure it has clear value.

Makes sense to wait!

view this post on Zulip Brendan Hansknecht (Jun 20 2024 at 20:53):

It would be a andThen ability. Is that enough to be consider a monad ability? But yeah, roughly that.

view this post on Zulip Kilian Vounckx (Jun 20 2024 at 20:56):

Brendan Hansknecht said:

It would be a andThen ability. Is that enough to be consider a monad ability? But yeah, roughly that.

I am totally against calling it Monad by the way.
Monad needs a return too. Like Ok in Result, Task.ok in Task, Core.const in the roc-parser package etc. But explicitly using these functions at the end of a block works just as well. Doesn't need to be part of the ability

view this post on Zulip Kilian Vounckx (Jun 20 2024 at 20:57):

Brendan Hansknecht said:

But I understand that ! causes a ton of confusion for new users and turns people away from the language so we want to remove it if possible. Personally, I wish I could define ! on any opaque type. That would make me happy.

if ! causes confusion and is removed, but <- is also removed, what is left over? Or was this a typo and would only <- be removed? I haven't seen people saying ! is confusing

view this post on Zulip Brendan Hansknecht (Jun 20 2024 at 21:08):

Sorry, typo

view this post on Zulip Kilian Vounckx (Jun 20 2024 at 21:08):

no problem

view this post on Zulip Brendan Hansknecht (Jun 20 2024 at 21:09):

<-: deprecated and likely to be removed
! for Task: Here to staty
! for other types: might happen one day if there is enough demand and it isn't considered too confusing.
? for Result: Was another floated idea...probably won't happen.

view this post on Zulip Notification Bot (Jun 21 2024 at 02:30):

20 messages were moved from this topic to #ideas > early return operator for Result by Richard Feldman.

view this post on Zulip Ian McLerran (Jun 21 2024 at 06:06):

I gotta say, I’m going to miss the <- back passing syntax too… ! await covers a lot of use cases, but it is really nice to be able to pull nested lambdas down to one indentation level.

I was in the camp of people who found it confusing at first, but I actually just wonder if the tutorial section on that needed a little reworking, as now it seems like a totally straightforward concept.


Last updated: Jul 06 2025 at 12:14 UTC