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?
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
Yep, second example is preferred
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
?
It's really bittersweet to me... But assuming !
goes well and uses of <-
are pretty low, the plan is to eventually fully remove it.
Personally, I like <-
for generators and results.
Yeah, I use it for result a lot too. But the extended !
syntax could cover that
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.
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.
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?
Brendan Hansknecht said:
But the extended
!
syntax could cover thatWe 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!
It would be a andThen
ability. Is that enough to be consider a monad ability? But yeah, roughly that.
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
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
Sorry, typo
no problem
<-
: 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.
20 messages were moved from this topic to #ideas > early return operator for Result by Richard Feldman.
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