TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The Tardis Monad

45 点作者 isaac21259大约 3 年前

7 条评论

stepchowfun大约 3 年前
People often say state is hard in functional programming, but things like the Tardis monad have convinced me that (semantically speaking) functional programming is even better at state than the imperative/OOP paradigms. Imperative programs are essentially restricted to one global monad implicitly hardcoded into the language semantics, whereas with functional programming you have the freedom to choose the most appropriate monad for the task at hand. You want state? Use the state monad. You want continuations? Use that monad. You want time traveling? Yep, there's a monad for that too. IO, randomness, nondeterminism, parallelism, environment variables, failure, backtracking, software transactional memory, you name it. Many problems are best solved with a custom monad, rather than one of the standard ones; for example, using a monad that allows your code to emit constraints to be solved (this is a common technique for implementing type inference in compilers). Satisfyingly, reifying effects with monads preserves referential transparency and is therefore compatible with laziness, unlike traditional side effects which are sensitive to evaluation order.
评论 #30903250 未加载
rssoconnor大约 3 年前
Unbelievably, I actually used this in a project when I found myself thinking that I needed a combination of a forward and backward propagating state monad.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;ElementsProject&#x2F;simplicity&#x2F;blob&#x2F;35627fc49ad96fcb844cca72ffbc69b6e934cb4c&#x2F;Haskell&#x2F;Core&#x2F;Simplicity&#x2F;LibSecp256k1&#x2F;Spec.hs#L548" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ElementsProject&#x2F;simplicity&#x2F;blob&#x2F;35627fc49...</a>
cwillu大约 3 年前
Time travel is all well and good, but it&#x27;s not a Tardis if it&#x27;s not bigger on the inside.
jasonincanada大约 3 年前
I just coded an example usage of this monad last week:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;jasonincanada&#x2F;kattis&#x2F;blob&#x2F;master&#x2F;src&#x2F;Pivot.hs#L62" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jasonincanada&#x2F;kattis&#x2F;blob&#x2F;master&#x2F;src&#x2F;Pivo...</a><p>This tests each element of a list to see if it&#x27;s a pivot, meaning it&#x27;s between the maximum to the left and the minimum to the right. In a single logical traversal it shouldn&#x27;t be able to see the minimum yet, since it hasn&#x27;t visited those elements. With reverse state you pretend you can anyway and let Haskell figure out the dependencies during execution
isaac21259大约 3 年前
Se also: <a href="https:&#x2F;&#x2F;tech-blog.capital-match.com&#x2F;posts&#x2F;5-the-reverse-state-monad.html" rel="nofollow">https:&#x2F;&#x2F;tech-blog.capital-match.com&#x2F;posts&#x2F;5-the-reverse-stat...</a>
lacrosse_tannin大约 3 年前
what the heck is the reverse state monad
评论 #30903208 未加载
dmead大约 3 年前
Isnt this just a lens?