News for hackers. Stuff that matters.
Re:The Registers of Rust by couchand on Wednesday March 08, 2023 @02:03PM (#35073313)
> There's no third axis for fallibility, because Dart chooses to comprehensively use exceptions for operations that fail (which I quite like).

Can you catch exceptions? Can you catch them when thrown iterating an Iterable, awaiting a Future, or iteratively awaiting values from a Stream?

It doesn't seem like you can get around needing fallibility. What if I have an asynchronous operation that can fail? What if I need a sequence of possibly-empty values?

Re:The Registers of Rust by munificent on Wednesday March 08, 2023 @02:27PM (#35073598)
As klodolph says, there's no axis for fallibility because the language doesn't offer different choices of fallibility strategy. There's just one: exceptions.

You can catch exceptions. If an iterator throws, you can catch that by surrounding the for loop in a try catch block.

Futures are sort of like Result types in that a Future can complete with either a value or an error. Exceptions inside asynchronous functions are automatically caught and wrapped into error futures, which then propagate out through the returned future object. When you await a future, if the future completes with an error, that then gets unwrapped back into a thrown exception.

Re:The Registers of Rust by steveklabnik on Wednesday March 08, 2023 @02:29PM (#35073619)
> Futures are sort of like Result types in that a Future can complete with either a value or an error.

Incidentally, for curious readers, the first version of the Future trait in Rust always returned a Result<T, E> from its poll method. The second version decided to instead return T directly, since T could be Result<T, E> too, making things a bit more general, but also leading to a tiny bit of type tetris.

Doesn't mean that I'm saying anything about whatever Dart does here, just that I also think there's a connection here :)

Re:The Registers of Rust by klodolph on Wednesday March 08, 2023 @02:15PM (#35073441)
> It doesn't seem like you can get around needing fallibility.

There’s no axis for fallability because all operations are fallible. Yes, you can catch exceptions when iterating, awaiting, or iteratively awaiting. You have fallibility. What you don’t have is a way of marking operations as non-fallible.

Re:The Registers of Rust by satvikpendem on Wednesday March 08, 2023 @03:21PM (#35074234)
If you use something like fpdart, you have the more functional Either type (called Result in Rust).

https://pub.dev/packages/fpdart#eitherlibsrceitherdart