Remix.run Logo
nh2 2 hours ago

Haskell is the king of cancellation. Using asynchronous exceptions, you can cancel anything, anytime, with user -defined exception types so you know what the cancellation reason is.

Example:

    maybeVal <— timeout 1000000 myFunction
Some people think that async exceptions are a pain because you nerd to be prepared that your code can be interrupted any time, but I think it's absolutely worth it because in all the other languages I encounter progress bars that keep running when I click the cancel button, or CLI programs that don't react to CTRL+C.

In Haskell, cancellability is the default and carries no syntax overhead.

This is one of the reasons why I think Haskell is currently the best language for writing IO programs.

ashishb an hour ago | parent [-]

How do it work inside `myFunction1` which is invoked by `myFunction`? Does `myFunction1` needs to be async as well?

jose_zap 26 minutes ago | parent [-]

No, it can be any pure function or IO. Both will get interrupted.