3 ms·
Roc actually doesn't use algebraic effects under the hood, although errors can naturally accumulate in a way that makes the code look more like error handling i
by rtfeldman 2y ago
Roc actually doesn't use algebraic effects under the hood, although errors can naturally accumulate in a way that makes the code look more like error handling in algebraic effects systems:
https://www.roc-lang.org/tutorial#task-failure https://www.roc-lang.org/tutorial#task-failure
The implementation detail that makes this error handling possible is that Roc uses anonymous sum types called "tags" (OCaml calls them polymorphic variants) that can accumulate on the fly:
https://www.roc-lang.org/tutorial#tags https://www.roc-lang.org/tutorial#tags
- tkz1312 2y agoVery interesting, thanks for the clarification. What is the difference between algebraic effects and rocs approach?
- rtfeldman 2y agoIn Haskell terms, Roc's `Task ok err` is essentially an `IO (Either err ok)` - the only difference between how Roc does it and how Haskell does it is that `Task` bakes in error handling whereas `IO` doesn't. (Plus the syntax sugar being different, of course.) So the biggest difference is that algebraic effects are a separate language feature, whereas Task (like IO in Haskell) is a plain old type in the standard library that happens to represent effeects. Incidentally, the Task.await function in Roc is based on Elm's Task.andThen - we just tried out a different name and argument order for it: https://package.elm-lang.org/packages/elm/core/latest/Task#andThen https://package.elm-lang.org/packages/elm/core/latest/Task#a...