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 I/O is pure

75 pointsby crntaylorover 12 years ago

9 comments

ambrop7over 12 years ago
C is also pure. After all, C code is just data until it gets compiled and executed. When and how often this happens is irrelevant. You could write a C interpreter in Haskell, and then your C code would be as pure as anything else in Haskell!
评论 #5193927 未加载
评论 #5194207 未加载
评论 #5194219 未加载
评论 #5194226 未加载
评论 #5194329 未加载
donsover 12 years ago
Looks like a reimplementation of Wouter Swiestra's work on a functional model of IO,<p><a href="http://www.staff.science.uu.nl/~swier004/Publications/BeautyInTheBeast.pdf" rel="nofollow">http://www.staff.science.uu.nl/~swier004/Publications/Beauty...</a><p>Author = {Wouter Swierstra and Thorsten Altenkirch}, Booktitle = {Haskell '07: Proceedings of the ACM SIGPLAN Workshop on Haskell}, Title = {Beauty in the Beast: A Functional Semantics of the Awkward Squad}, Pages = {25--36}, Location = {Freiburg, Germany}, Year = {2007}}
评论 #5194436 未加载
评论 #5193895 未加载
Zr40over 12 years ago
Permalink: <a href="http://chris-taylor.github.com/blog/2013/02/09/io-is-not-a-side-effect/" rel="nofollow">http://chris-taylor.github.com/blog/2013/02/09/io-is-not-a-s...</a>
评论 #5193705 未加载
evincarofautumnover 12 years ago
So basically, “main” is not an impure function. It’s a pure value representing an impure function. A monad is essentially a data type that represents computations in some domain-specific language, using data (return) and code (&#62;&#62;=) from the host language. The <i>only</i> thing special about the IO datatype is that the impure Haskell runtime can evaluate it.
A1kmmover 12 years ago
If you want to do this in practice rather than as a specialised example, I would suggest using something like Conduit, rather than reinventing the wheel.<p>Conduit is used widely in the Yesod web framework (for example, to implement the HTTP server), and could easily be hooked up to stdin and stdout for an interactive pure program.<p>Conduit internally looks like this: <a href="http://hackage.haskell.org/packages/archive/conduit/0.5.6/doc/html/Data-Conduit-Internal.html" rel="nofollow">http://hackage.haskell.org/packages/archive/conduit/0.5.6/do...</a> - note that you get to choose an underlying monad m and run things in it using PipeM, but you could just make this the Identity monad.
jeremyjhover 12 years ago
I had an "aha" moment here - very nice little article.
评论 #5194442 未加载
ibottyover 12 years ago
see <a href="https://news.ycombinator.com/item?id=5193368" rel="nofollow">https://news.ycombinator.com/item?id=5193368</a> for another submission.
dschiptsovover 12 years ago
What is the point of having this "mini-language"?<p>What would happen to purity if I hit ^D?)
评论 #5194071 未加载
millstoneover 12 years ago
If Haskell I/O is pure, why can't it be intermingled with other pure functions?
评论 #5193976 未加载
评论 #5193905 未加载