News for hackers. Stuff that matters.
Re:Functional Semantics in Imperative Clothing (Richard Feld... by tkz1312 on Monday April 29, 2024 @09:26AM (#40198052)
Roc has algebraic effects instead of Monads for effect tracking. The two systems are exactly as expressive as each other [1]. Algebraic effects compose better than Monads, and are probably more beginner friendly. Imo Monadic code can be a little easier to follow sometimes since there’s less non-local control flow. They are both great things to have in a language and I’m super excited to see how much progress Roc is making in both approachability and performance when it comes to pure functional programming.

[1]: https://homepages.inf.ed.ac.uk/slindley/papers/effmondel-jfp...

Re:Functional Semantics in Imperative Clothing (Richard Feld... by rtfeldman on Monday April 29, 2024 @10:30AM (#40198783)
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

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

Re:Functional Semantics in Imperative Clothing (Richard Feld... by tkz1312 on Monday April 29, 2024 @11:06AM (#40199276)
Very interesting, thanks for the clarification. What is the difference between algebraic effects and rocs approach?
Re:Functional Semantics in Imperative Clothing (Richard Feld... by rtfeldman on Monday April 29, 2024 @11:23AM (#40199527)
In 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#a...

Re:Functional Semantics in Imperative Clothing (Richard Feld... by bedobi on Monday April 29, 2024 @10:45AM (#40198998)
can someone explain in plain English and with some easy to understand code examples?
Re:Functional Semantics in Imperative Clothing (Richard Feld... by ngruhn on Monday April 29, 2024 @11:13AM (#40199380)
But do algebraic effects preserve referential transparency? It’s hard for me to see that they do.