4 ms·
Algebraic Effects – You Can Touch This (2019)
- tuukkah 4y agoConsidering that React with function components is popular and their hook mechanism is seemingly weird, should people also learn algebraic effects as the beautiful theory behind it? Also, if React hooks is the way to describe UI components, I think the mechanism behind it should be either formalised as a proper language feature in JS or in some new language used for frontend development. For example, I noticed this teaser bit in the first materials about Verse: "The full Verse language also has a statically-checked effect system, including both mutable references and input/output." https://simon.peytonjones.org/verse-calculus/ https://simon.peytonjones.org/verse-calculus/ Discussed earlier here: https://news.ycombinator.com/item?id=33946933 https://news.ycombinator.com/item?id=33946933 Or is this something that e.g. ClojureScript with Reagent already formalises and we all should study that?
- seer 4y agoWell there's https://crank.js.org https://crank.js.org that uses native js generators where you would you normally put hooks in. Never used it but looked like a very neat idea. I believe Reagent utilises Clojure's native "atom" to accomplish what hooks try to do but with much better language level guarantees. I guess what js needs is an actual proper language level immutable type, and it wouldn't need all the hooks trickery?
- vintermann 4y ago> Conditions and restarts are kind of like try/throw exception handling you know from more mainstream languages, except much more powerful. This reminds me of the arguments for call/cc in scheme. A very general construct! It can implement exceptions, backtracking, it can even implement "if", so "if" wouldn't even need to be primitive. You know what else lets you do all that? Good old GOTO. I don't care about "power" for a language construct. I need guarantees a lot more. Does using this construct allow me to put some things in the "that doesn't matter here" bin, so I can focus on some things without worrying about everything at once? GOTO is better at punching holes in bins of compartmentalization, and call/cc isn't much better. I don't know much about algebraic effects, but usually "algebraic" implies various guarantees about composability and idempotence, which are exactly what you want when dealing with state and the world.
- Corazoor 4y agoOne 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.
- vintermann 4y agoI 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 4y agoYeah 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 4y ago> GOTO ist not bound to any scope Are you sure about that?
- gpderetta 4y agosetjmp/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.
- artemonster 4y ago> I don't know much about the scope of the theoretical work there. The missing ingredient is implied to be "continuations", which are not supported in Common Lisp. „I have a partial understanding of a related concept and zero knowledge on the actual topic, so let me write a blog post“ CL condition system is a strict subset of algebraic effects (or any effect system)
- TeMPOraL 4y ago> „I have a partial understanding of a related concept and zero knowledge on the actual topic, so let me write a blog post“ Would you prefer me to not write about related concepts I do know about, or just to omit the disclaimer next time and confidently pretend I know everything?
- artemonster 4y agoI have no preferences, you do you. Kudos for putting the disclaimer :)
- xiaodai 4y agoIs "Conditions and Restarts" related to delimited continuation?
- gpderetta 4y agoas far as I understand, yes.
- nerdponx 4y agoI believe restarts are a special case of invoking a continuation. The difference in Lisp is that you can't actually capture and pass around the continuation as a first class object, like you can in Scheme, and I don't believe there is a way to invoke more than one restart for a given condition. I think this limited special case covers the majority of what people would want to do with continuations, and prevents people from doing the messy stuff that you shouldn't be doing anyway. From what I recall, the new algebraic effects system in OCaml has similar limitations (you can only invoke the continuation once), and I think Koka has a special case for it in their compiler & encourages it.