top | item 33981992

(no title)

Corazoor | 3 years ago

One big difference: GOTO ist not bound to any scope. Which ist no wonder, its usually just syntactic sugar for an omnipresent assembly instruction: JMP.

Algebraic effects are less general and play nicer with scoped constructs like finalizers and exceptions. The downside is that they work via stack unwindindig, so they incur some performace penalties.

I highly recommend reading the original article - "Algebraic Effects for the Rest of Us". It demonstrates their operation via Javascript by renaming try/catch, and I think it will answer your questions nicely.

discuss

order

vintermann|3 years ago

I know that, and I did read that article. I wasn't criticising algebraic effects, I suggested it may indeed have something on the mere "power" of constructs that can implement the same flow.

That said, the article didn't make me much wiser on what's the point. I could sort of see it if it came with guarantees in the type system, I guess.

Corazoor|3 years ago

Yeah thats fair I guess, it IS hard to see whats so special about it.

Imho, it's the same deal as with monads: Outside of pure functional languages with a strong type system there is not much appeal. But for e.g. a Haskell programmer its like the next coming of christ...

But I think it could be very useful if combined with the equivalent of javas checked exceptions, even in other languages.

Something like "fun readFile(Name: Path):String performs FS.open, FS.read, FS.close throws FileNotFound, FileRead, ..."

A bit excessive, but potentially very useful for all kinds of error checking.

lispm|3 years ago

> GOTO ist not bound to any scope

Are you sure about that?

Corazoor|3 years ago

Hah, when I wrote that I was thinking of qualifying it a bit better to prevent the very obvious objections.

It really depends on the language and what kind of goto you mean.

But in the context of the post I replied to, yes, because you cannot replace algebraic effects with "neutered" gotos (like the ones in c), you need the equivalent of longjmp, or maybe gosub.

You can obviously design a language where goto does implicitely run finalizers or does similar fancy stuff, but this is again leaving the scope of the original discussion I think...

AnimalMuppet|3 years ago

Depends on the language, I think?

Assembly lets you jump anywhere, not bound by any scope, because it doesn't have scopes in any real sense.

C and Pascal, if I recall correctly, only let you goto somewhere else in the same function.

Don't know about other languages...

gpderetta|3 years ago

setjmp/longjmp (aka goto on steroid) is a better example. Algebraic effects are sort of a structured (and, depending on the language, typed) form of sjlj.