TE
TechEcho
StartseiteTop 24hNeuesteBesteFragenZeigenJobs
GitHubTwitter
Startseite

TechEcho

Eine mit Next.js erstellte Technologie-Nachrichtenplattform, die globale Technologienachrichten und Diskussionen bietet.

GitHubTwitter

Startseite

StartseiteNeuesteBesteFragenZeigenJobs

Ressourcen

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. Alle Rechte vorbehalten.

Why Algebraic Effects?

292 Punktevon jiggawattsvor 5 Tagen

28 comments

nemo1618vor 5 Tagen
I see two downsides. Looking at this snippet:<p><pre><code> my_function (): Unit can AllErrors = x = LibraryA.foo () y = LibraryB.bar () </code></pre> The first thing to note is that there is no indication that foo or bar can fail. You have to lookup their type signature (or at least hover over them in your IDE) to discover that these calls might invoke an error handler.<p>The second thing to note is that, once you ascertain that foo and bar can fail, how do you find the code that will run when they <i>do</i> fail? You would have to traverse the callstack upwards until you find a &#x27;with&#x27; expression, then descend into the handler. And this cannot be done statically (i.e. your IDE can&#x27;t jump to the definition), because my_function might be called from any number of places, each with a different handler.<p>I do think this is a really neat concept, but I have major reservations about the readability&#x2F;debuggability of the resulting code.
评论 #44079283 未加载
评论 #44079006 未加载
评论 #44079099 未加载
评论 #44079019 未加载
评论 #44078962 未加载
评论 #44079143 未加载
评论 #44080642 未加载
评论 #44080664 未加载
评论 #44081321 未加载
评论 #44085450 未加载
AdieuToLogicvor 5 Tagen
&gt; You can think of algebraic effects essentially as exceptions that you can resume.<p>How is this substantively different than using an ApplicativeError or MonadError[0] type class?<p>&gt; You can “throw” an effect by calling the function, and the function you’re in must declare it can use that effect similar to checked exceptions ...<p>This would be the declared error type in one of the above type classes along with its `raiseError` method.<p>&gt; And you can “catch” effects with a handle expression (think of these as try&#x2F;catch expressions)<p>That is <i>literally</i> what these type classes provide, with a &quot;handle expression&quot; using `handleError` or `handleErrorWith` (depending on need).<p>&gt; Algebraic effects1 (a.k.a. effect handlers) are a very useful up-and-coming feature that I personally think will see a huge surge in popularity in the programming languages of tomorrow.<p>Not only will &quot;algebraic effects&quot; have popularity &quot;in the programming languages of tomorrow&quot;, they <i>actually</i> enjoy popularity in programming languages today.<p><a href="https:&#x2F;&#x2F;typelevel.org&#x2F;cats&#x2F;typeclasses&#x2F;applicativemonaderror.html" rel="nofollow">https:&#x2F;&#x2F;typelevel.org&#x2F;cats&#x2F;typeclasses&#x2F;applicativemonaderror...</a>
评论 #44079768 未加载
评论 #44079034 未加载
评论 #44078861 未加载
评论 #44078821 未加载
评论 #44082248 未加载
评论 #44080731 未加载
评论 #44079214 未加载
评论 #44078727 未加载
practalvor 5 Tagen
Algebraic effects seem very interesting. I have heard about this idea before, but assumed that it somehow belonged into the territory of static type systems. I am not a fan of static type systems, so I didn&#x27;t look further into the idea.<p>But I found these two articles [1] about an earlier <i>dynamic</i> version of Eff (the new version is statically typed), which explains the idea nicely without introducing types or categories (well, they use &quot;free algebra&quot; and &quot;unique homomorphism&quot;, just think &quot;terms&quot; and &quot;evaluation&quot; instead). I find it particularly intriguing that what Andrej Bauer describes there as &quot;parameterised operation with generalised arity&quot;, I would just call an abstraction of shape [0, 1] (see [2]). So this might be helpful for using concepts from algebraic effects to turn abstraction algebra into a programming language.<p>[1] <a href="https:&#x2F;&#x2F;math.andrej.com&#x2F;2010&#x2F;09&#x2F;27&#x2F;programming-with-effects-i-theory&#x2F;" rel="nofollow">https:&#x2F;&#x2F;math.andrej.com&#x2F;2010&#x2F;09&#x2F;27&#x2F;programming-with-effects-...</a><p>[2] <a href="http:&#x2F;&#x2F;abstractionlogic.com" rel="nofollow">http:&#x2F;&#x2F;abstractionlogic.com</a>
评论 #44079518 未加载
michalsustrvor 5 Tagen
AE (algebraic effect) are very interesting! Great article, thank you.<p>Reading through, I have some concerns about usability in larger projects, mainly because of &quot;jumping around&quot;.<p>&gt; Algebraic effects can also make designing cleaner APIs easier.<p>This is debatable. It adds a layer of indirection (which I concede is present in many real non-AE codebases).<p>My main concern is: When I put a breakpoint in code, how do I figure out where the object I work with was created? With explicit passing, I can go up and down the stack trace, and can find it. But with AE composition, it can be hard to find the instantiation source -- you have to jump around, leading to yo-yo problem [1].<p>I don&#x27;t have personal experience with AE, but with python generators, which the article says they are the same (resp. AE can be used to implement generators). Working through large complex generator expressions was very tedious and error-prone in my experience.<p>&gt; And we can use this to help clean up code that uses one or more context objects.<p>The functions involved still need to write `can Use Strings` in their signature. From practical point of view, I fail to see the difference between explicitly passing strings and adding the `can Use Strings` signature -- when you want add passing extra context to existing functions, you still need to go to all of them and add the appropriate plumbing.<p>---<p>As I understand it, AE on low level is implemented as a longjmp instruction with register handling (so you can resume). Given this, it is likely inevitable that in a code base where you have lots of AE, composing in various ways, you can get to a severe yo-yo problem, and getting really lost in what is the code doing. This is probably not so severe on a single-person project, but in larger teams where you don&#x27;t have the codebase in your head, this can be huge efficiency problem.<p>Btw. if someone understands how AE deal with memory allocations for resuming, I&#x27;d be very interested in a good link for reading, thank you!<p>[1]: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Yo-yo_problem" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Yo-yo_problem</a>
评论 #44085281 未加载
评论 #44085206 未加载
huqedatovor 5 Tagen
This Ante &quot;pseudocode&quot; is wonderful! It&#x27;s like Haskell with Elixir&#x27;s expressiveness, flavor and practicality. A Haskell for developers. Waiting for the compiler to mature. I would love to develop apps in Ante.
cdaringevor 5 Tagen
I did protohackers in ocaml 5 alpha a couple of years ago with effects. It was fun, but the toolchain was a lil clunky back then. This looks and feels very similar. Looking forward to seeing it progressing.
评论 #44078990 未加载
wild_eggvor 5 Tagen
&gt; You can think of algebraic effects essentially as exceptions that you can resume.<p>So conditions in Common Lisp? I do love the endless cycle of renaming old ideas
评论 #44079128 未加载
评论 #44078921 未加载
评论 #44082087 未加载
评论 #44079244 未加载
charcircuitvor 5 Tagen
This doesn&#x27;t give a focused explaination on why. I don&#x27;t see how dependency injection is a benefit when languages without algebraic effects also have dependency injection. It doesn&#x27;t explain if this dependency injections is faster to execute or compile or what.
评论 #44079329 未加载
评论 #44078818 未加载
评论 #44084381 未加载
dupedvor 4 Tagen
I often see the claim that AE generalizes control flow, so you can (for example) implement coroutines. But the most obvious way I would implement AE in a language runtime is with coroutines, where effects are just syntactic sugar around yield&#x2F;resume.<p>What am I missing?
评论 #44083228 未加载
评论 #44083110 未加载
评论 #44083845 未加载
nevertoolatevor 5 Tagen
When I see a new (for me) idea coming from (presumably) category theory I wonder if it really will land in any mainstream language. In my experience having cohesion on the philosophical level of the language is the reason why it is nice to work with it in a team of programmers who are adept in both programming and in the business context. A set of programming patterns to solve a problem usually can be replaced with a possibly disjunct set of patterns where both solutions have all the same ilities in the code and solve the business problem.<p>My question is - can a mainstream language adopt the algebraic effects (handlers?) without creating deep confusion or a new language should be built from the ground up building on top of these abstractions in some form.
评论 #44079680 未加载
评论 #44084256 未加载
评论 #44079596 未加载
hcarvalhoalvesvor 4 Tagen
What once was old is new again.<p><a href="https:&#x2F;&#x2F;lisp-docs.github.io&#x2F;cl-language-reference&#x2F;chap-9&#x2F;j-b-condition-system-concepts" rel="nofollow">https:&#x2F;&#x2F;lisp-docs.github.io&#x2F;cl-language-reference&#x2F;chap-9&#x2F;j-b...</a><p><a href="https:&#x2F;&#x2F;jacek.zlydach.pl&#x2F;blog&#x2F;2019-07-24-algebraic-effects-you-can-touch-this.html" rel="nofollow">https:&#x2F;&#x2F;jacek.zlydach.pl&#x2F;blog&#x2F;2019-07-24-algebraic-effects-y...</a>
aatd86vor 5 Tagen
I might be a bit dense but I didn&#x27;t quite get it and the examples didn&#x27;t help me. For instance, the first example SayMessage. Is it supposed to be an effect? Why? From the function signature it could well be a noop and we wouldn&#x27;t know the difference. Or is it arbitrarily decided? Is this all about notations for side-effectful operations?
评论 #44080970 未加载
评论 #44080877 未加载
z5hvor 4 Tagen
After spending a lot if time in Prolog, I want a nice way to implement and compose nondeterministic functions and also have a compile time type check. I’m eyeing all of these languages as a result. I’ll watch Ante as well. (Don’t forget developer tools like an LSP, tree-sitter or other editor plugins).
评论 #44083479 未加载
codethiefvor 3 Tagen
Great blog post! I only have a theoretical understanding of algebraic effects so far and have yet to use them in practice, so please excuse this likely dumb question: In functional&#x2F;declarative programming languages variable declarations can be evaluated in any order, as long as they don&#x27;t depend on each other. Now if both declarations involve calls to functions with side effects, what determines the order in which these effects will be executed?
评论 #44092654 未加载
thrancevor 5 Tagen
I like the idea of Algebraic effects but I&#x27;m a little skeptical of the amount of extra syntax.<p>Let&#x27;s say I&#x27;m building a web server, my endpoint handler now needs to declare that it can call the database, call the s3, throw x, y and z... And same story for most of the functions it calls itself. You solved the &quot;coloration problem&quot; at the cost of adding a thousand colors.<p>Checked exceptions are the ideal error handling (imho) but no one uses them properly because it&#x27;s a hassle declaring every error types a function may return. And adding an exception to a function means you need to add&#x2F;handle it in many of its callers, and their callers in turn, etc.
评论 #44081480 未加载
nikita2206vor 5 Tagen
Have you thought of using generators as a closest example to compare effects to? I think they are much closer to effects than exceptions are. Great explainer anyway, it was tge first time I have read about this idea and it was immediately obvious
评论 #44084214 未加载
评论 #44079367 未加载
rixedvor 5 Tagen
Maybe I&#x27;m too archaic but I do not share the author&#x27;s hope that algebraic effects will ever become prevalently used. They certainly can be useful now and then, but the similitude with dynamic scoping brings too many painful memories.
评论 #44079295 未加载
evelantvor 4 Tagen
This is neat, but you don’t need a new language to leverage these concepts. <a href="https:&#x2F;&#x2F;effect.website&#x2F;" rel="nofollow">https:&#x2F;&#x2F;effect.website&#x2F;</a> The effect library brings all of this goodness to typescript (and then some) and is robust and production ready. I hate writing typescript without it these days.
评论 #44084202 未加载
评论 #44081526 未加载
carterschonwaldvor 4 Tagen
I kinda want algebraic effects but where you can locally declare that certain effects are implicit&#x2F;invisible in the types.
评论 #44084242 未加载
yyykvor 5 Tagen
The state effects example seems unlike the others - the examples avoid syntax for indentation, omit polymorphic effect mention and use minimal syntax for functions - but for state effects you need to repeat &quot;can Use Strings&quot; each function? Presumably one may want to group those under type Strings or can Use Strings, at which point you have a namespace of sorts...
xixixaovor 5 Tagen
It feels powerful. I think the effects in return types could be inferred.<p>But I share the concerns of others about the downsides of dependency injection. And this is DI on steroids.<p>For testing, I much prefer to “override” (mock) the single concrete implementation in the test environment, rather than to lose the static caller -&gt; callee relationship in non-test code.
artemonstervor 5 Tagen
With AE you get for free: generators, stackful coroutines, dependency injection, &quot;dynamic&quot; variables (as in anti-lexical ones), resumable exceptions, advanced error handling and much more. all packaged neatly into ONE concept. I dream of TS and Effekt some day merging :)
评论 #44081492 未加载
riyazahujavor 5 Tagen
What’s the advantage here of using effects over monads? It seems to me that all the proposed benefits of effects are reproducible&#x2F;reproduced already by monads. Is it simply to get stateful actions while still being pure in a <i>dynamic</i> type system rather than static?
评论 #44082527 未加载
评论 #44084284 未加载
ollysbvor 5 Tagen
As I understand it this was the inspiration for React&#x27;s hooks model. The compiler won&#x27;t give you the same assurances but in practice hooks do at least allow to inject effects into components.
评论 #44079199 未加载
评论 #44079200 未加载
knuckleheadsvor 5 Tagen
First time in a long while where I’ve read the intro to a piece about new programming languages and not recognized any of the examples given at all even vaguely. How times change!
ChuckMcMvor 4 Tagen
As a coding abstraction I really like this (not sure I&#x27;m completely understanding it, but it sounds handy.) I wonder if that&#x27;s because I spent a couple of years doing kernel programming at Sun? Its nice to be able to write sleep(foo) and know that when your code starts running again after that it&#x27;s because foo woke you up. That saves a ton of time wiring up control flow and trying to cover all the edge cases. Caveat the memory locality question, it would be fun to initialize all your functions waiting to catch a unit to work on and then writing your algorithm explicitly in unit mutations.
thdhhghgbhyvor 5 Tagen
Just seems to be a way of organising code really.
评论 #44083278 未加载
nabla9vor 5 Tagen
Yet another thing Common Lisp programmers have been doing since the time of hoe and axe.
评论 #44079355 未加载