TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Exotic Programming Ideas, Part 3: Effect Systems

293 pointsby psibiover 4 years ago

11 comments

sirabenover 4 years ago
I highly recommend Oleg Kiselyov&#x27;s talk titled &quot;Having an Effect&quot;[0] in which he talks about<p>- purely functional model of computation and its pitfalls<p>- Actor model, effectful programming with requests and responses and an implementation in Haskell.<p>- denotational semantics and combining effects. Once you have a model of your language, what if you want to extend it by adding another effect? It forces you to rewrite the semantics (and thus any interpreter of your language) completely. Taking using the effects-as-requests viewpoint, only the request and handler for an effect needs to be added or changed, and the rest untouched. This is known as &quot;stable denotations&quot;.<p>- really evaluating what it means for an expression to be pure or effectful. Even variable reference should be considered an effect.<p>- different scoping rules in lambda calculus can be expressed in terms of effects! Creating a dynamic closure is not effectful, though applying it usually is, OTOH, creating a lexical closure is effectful but using it is not.<p>I think Haskell provides a good example of how a purely functional language can still express effectful computation. through a monadic interface. Though monad transformers have their share of problems when heavily nested (n^2 instances, performance), various effect system libraries are gaining traction.[2] On the bleeding edge of research there&#x27;s languages like Frank[1] where the effect system is pervasive throughout the language.<p>[0] <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=GhERMBT7u4w" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=GhERMBT7u4w</a><p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;frank-lang&#x2F;frank" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;frank-lang&#x2F;frank</a><p>[2] Implementing free monads from scratch, <a href="https:&#x2F;&#x2F;siraben.github.io&#x2F;2020&#x2F;02&#x2F;20&#x2F;free-monads.html" rel="nofollow">https:&#x2F;&#x2F;siraben.github.io&#x2F;2020&#x2F;02&#x2F;20&#x2F;free-monads.html</a>
评论 #25179060 未加载
评论 #25180697 未加载
评论 #25183584 未加载
评论 #25178757 未加载
评论 #25184887 未加载
skybrianover 4 years ago
I expect that, as with any other type system extension, the more granular your effects are, the more likely you are to run into a “what color is my function” problem. If you have a public API that declares certain effects, you’re stuck with those unless you break backward compatibility.<p>In a practical system, when writing a library and especially an abstract interface, you’d want to be careful what you promise and declare effects that you might need (but currently don’t use), just in case you will need them later.<p>It’s not that easy even to distinguish functions that can fail from those that can’t, if you’re trying to anticipate how a system will evolve. Something that’s in-memory now might change to being done over the network later.
评论 #25179878 未加载
评论 #25182768 未加载
评论 #25179424 未加载
评论 #25180661 未加载
评论 #25183694 未加载
评论 #25179596 未加载
评论 #25194000 未加载
ianbickingover 4 years ago
I&#x27;ve had this idea of &quot;dynamic returns&quot; (akin to dynamic scope) in my head for a while. Reading this, it feels like a dynamically typed companion to effect systems.<p>The idea of a dynamic return is just to give a formal way to accumulate things during a set of function calls, without having every function to be aware of what might be happening. In Python context managers are often used for this (e.g., contextlib.redirect_stdout to capture stdout), but thinking about it as another kind of return value instead of &quot;capturing&quot; would be an improvement IMHO. (You have to &quot;capture&quot; when hardcoded imperative code later needs to be retrofitted, but as it is retrofitting is all we have.)<p>But dynamic returns aren&#x27;t quite like an effect system unless you also create something more-or-less like a transaction or a changeset. We usually think about transactions as simply a way to rollback in case of an error, but as a changeset there&#x27;s all kinds of interesting auditing and logging and debugging possibilities. E.g., if your effect is writing to stdout, you could rewrite all those changes (e.g., apply a filter, or add a text prefix to each line).
评论 #25181645 未加载
评论 #25180411 未加载
评论 #25181992 未加载
aozgaaover 4 years ago
&gt; As far as I can tell no one uses this language [Koka] for anything, however it is downloadable and quite usable to explore these ideas.<p>I believe the typesetting tool Madoko[1] is implemented in Koka, though in fairness Daan Leijen developed both Koka and Madoko.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;koka-lang&#x2F;madoko" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;koka-lang&#x2F;madoko</a>
toolsliveover 4 years ago
Ocaml (almost ?) has it. <a href="https:&#x2F;&#x2F;www.janestreet.com&#x2F;tech-talks&#x2F;effective-programming&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.janestreet.com&#x2F;tech-talks&#x2F;effective-programming&#x2F;</a>
klodolphover 4 years ago
There&#x27;s some interesting research and ideas here, but it does seem like monads &quot;ate everything for lunch&quot; back in the late 1990s and 2000s when it comes to encoding effects, probably because monads are a bit more ergonomic (which seems like a weird thing to say, given the reputation monads have for being abstract nonsense). So effect systems didn&#x27;t get as much research as everyone was interested in monads, and now that monads have dried up a bit as a field of research for encoding effects, I&#x27;m interested to see what other systems people invent.
评论 #25194125 未加载
dustingetzover 4 years ago
It&#x27;s not just about marking regions and checking them, &quot;effect systems are fundamentally about dynamic dispatch (separating effect from effect handler)&quot; Alexis King
smegma2over 4 years ago
I was curious about this function:<p><pre><code> fun addRefs( a : forall&lt;h&gt; ref&lt;h,int&gt;, b : forall&lt;h&gt; ref&lt;h,int&gt; ) : total () { a := 10; b := 20; return (!a + !b); } </code></pre> Why is it total instead of st&lt;h&gt;? Won&#x27;t this have a side effect of setting the references?
评论 #25179695 未加载
The_rationalistover 4 years ago
Arrow Fx implement this idea for Kotlin -&gt; <a href="https:&#x2F;&#x2F;arrow-kt.io&#x2F;docs&#x2F;fx&#x2F;" rel="nofollow">https:&#x2F;&#x2F;arrow-kt.io&#x2F;docs&#x2F;fx&#x2F;</a>
评论 #25182799 未加载
transfireover 4 years ago
I believe Kitten is another language exploring this area.
PaulHouleover 4 years ago
&quot;Non-termination is an Effect&quot;
评论 #25179592 未加载
评论 #25179357 未加载
评论 #25179225 未加载