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.

Haskell’s State monad is not a monad (2014)

103 pointsby setraalmost 7 years ago

5 comments

lmmalmost 7 years ago
This isn&#x27;t about the state monad, it&#x27;s about seq. &quot;But now seq must distinguish ⊥ from λx → ⊥, so they cannot be equal. But they are eta-equivalent. We have lost eta equality!&quot; - once you lose eta equality you lose everything. A whole raft of monads become impossible, not just state.<p>Equivalence in Haskell is defined only up to ⊥; to work in Haskell we rely on the &quot;Fast and Loose Reasoning is Morally Correct&quot; result that <i>if</i> two expressions are equivalent-up-to-⊥. and both non-⊥ then they are equivalent.<p>(Or, y&#x27;know, work in Idris with --total and avoid this problem entirely).
评论 #17441551 未加载
评论 #17441760 未加载
评论 #17442221 未加载
carterschonwaldalmost 7 years ago
This is all pretty fun reading.<p>At least with my own code in Haskell, I work in the mental model where I assume termination and strong normalization (all programs terminate under all evaluation strategies).<p>Then, Bottom corresponds to either an exception that will get forced or a computationally boring infinite loop (which the rts can sometime detect and turn into an exception). My personal style favors having those errors be very very visible.<p>That said, depending on what formal or informal reasoning properties you care about (especially as a library writer), these little subtleties can be really important!
评论 #17444194 未加载
danabramsalmost 7 years ago
The real monad was the friends we made along the way.
pacalaalmost 7 years ago
Cute, but why should one care about ⊥, aka bottom, aka nontermination [0]? Let&#x27;s write programs that terminate...<p>[0] <a href="https:&#x2F;&#x2F;wiki.haskell.org&#x2F;Bottom" rel="nofollow">https:&#x2F;&#x2F;wiki.haskell.org&#x2F;Bottom</a>
评论 #17441451 未加载
评论 #17441867 未加载
评论 #17441709 未加载
评论 #17441271 未加载
dustingetzalmost 7 years ago
It seems to me a piece of software is either a formal proof or it&#x27;s not. So if it&#x27;s not and we still manage to write robust programs, the natural next question is, to what degree is it okay to knowingly violate the laws? And if you iterate that to the nth, do you end up with Clojure?
评论 #17441283 未加载