News for hackers. Stuff that matters.
Re:Hurl: A terrible but cute idea for a language by compscigirl on Monday June 19, 2023 @04:52PM (#36396301)
I feel like I must be missing something. It seems to me (just from reading this post) that if you need algebraic effects you’ve probably painted yourself into a corner and should probably reconsider your program’s architecture. It seems like a good way obscure what the code is really doing and end up with poorly organised spaghetti code. In the post he’s effectively making a function async while pretending it’s not, or calling a callback but making the top level code’s problem instead of encapsulating in the associated type. I’m sure there’s uses for algebraic effects down the line I haven’t thought of, but I don’t understand why these would be desired outcomes?
Re:Hurl: A terrible but cute idea for a language by duped on Monday June 19, 2023 @05:38PM (#36396804)
Look at it less like a first class language feature and more like a language feature for implementing others in terms of it.
Re:Hurl: A terrible but cute idea for a language by dvt on Monday June 19, 2023 @05:02PM (#36396423)
You're not missing anything. Algebraic effects are basically typed gotos†[1][2], and are generally a bad idea to use and/or implement. They can be useful in a few very niche situations when using typed functional languages.

† With added asynchronicity.

[1] http://community.schemewiki.org/?call-with-current-continuat...

[2] Some argue call/cc is, in fact, worse than goto: https://okmij.org/ftp/continuations/against-callcc.html

Re:Hurl: A terrible but cute idea for a language by habitue on Monday June 19, 2023 @05:50PM (#36396915)
loops are typed gotos, so are if statements, so, really are functions.

Goto isn't bad, it's integral to programming. It's just too powerful, so we tame it in various ways. Algebraic effects are one of those ways.

Re:Hurl: A terrible but cute idea for a language by dvt on Monday June 19, 2023 @05:59PM (#36397006)
> loops are typed gotos, so are if statements, so, really are functions.

All of the above don't break the continuity of a program's control flow. Maybe you should be arguing with Dijkstra, not me: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD02xx/E...

Pretty sure we've already litigated that goto/jmp is bad, which is why it's almost never used in modern C/C++ code unless doing very specific things.

Re:Hurl: A terrible but cute idea for a language by Turskarama on Monday June 19, 2023 @07:53PM (#36397948)
The big difference here is to understand the program with Algebraic effects you now need to know _where the code was called from_.

If you ask for an effect to come from higher up the call stack, does that mean part of the function signature needs to include that the call stack must be able to handle the effect?

And if that's part of the call stack, why not just make that an explicit function?

Re:Hurl: A terrible but cute idea for a language by duped on Monday June 19, 2023 @10:27PM (#36399006)
> Does that mean part of the function signature needs to include that the call stack must be able to handle the effect?

Some people would argue that the effects a function may raise are indeed a part of a function's type and for it to type check it must be within scope of a handler for that effect. Think of it like function coloring, a function with the "async/await" effect means all callees must be invoked either within an "async" block (another function with the await effect) or within scope of a runtime that handles the effect.

But even that is a bit limiting.

> And if that's part of the call stack, why not just make that an explicit function?

This is kind of a meaningless question depending on how you formulate it, because the big thing about things like effects is that the callee both returns more than once and is called more than once - so the notion of a "call stack" is kind of meaningless.

For example if f calls g and g raises E1 and then E2, f can declare a handler for E1 which moves it into a different scope that has a handler for E2. From the perspective of g() there is no function to call to deal with E1 and E2, since it's the responsibility of the caller to determine that.

Re:Hurl: A terrible but cute idea for a language by Turskarama on Tuesday June 20, 2023 @08:21PM (#36412668)
I think if you wanted to get weird with the control flow like this you might as well make a state machine. All of this seems to be completely missing the reason we even have stack based programs to begin with: they are inherently easier for programmers to reason about.

I think these effects would ultimately lead to a bunch of hard to find bugs, all to replace the functionality of a callback.