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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Haskell's Missing Concurrency Basics (2016)

114 点作者 DanielRibeiro大约 7 年前

8 条评论

fiorix大约 7 年前
There&#x27;s an open position at Facebook to work on GHC. If you&#x27;re into Haskell and want to make it better, here&#x27;s your opportunity: <a href="https:&#x2F;&#x2F;www.facebook.com&#x2F;careers&#x2F;jobs&#x2F;a0I1H00000MoVjBUAV&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.facebook.com&#x2F;careers&#x2F;jobs&#x2F;a0I1H00000MoVjBUAV&#x2F;</a>
dnautics大约 7 年前
How does erlang&#x2F;elixir do it? I&#x27;ve never really had any problems.
评论 #17045785 未加载
评论 #17048304 未加载
chriswarbo大约 7 年前
I had some sympathy for this situation, until I saw that the concurrency was being specified via a function called `mapConcurrently`.<p>IMHO this is perfectly acceptable behaviour for a `map` function, since that name has gained the connotation that its purpose is to transform one &#x27;collection&#x27; (Functor; whatever) into another, by pointwise, <i>independent</i> applications of the given function. Providing a function&#x2F;action which breaks this independence (by writing to the same handle) breaks this implicit meaning. Heck, I&#x27;d consider it a code smell to combine interfering actions like this using a <i>non-concurrent</i> `map` function; I would prefer to define a separate function to make this distinction explicit, e.g.<p><pre><code> -- Like &#x27;map&#x27;, but function invocations may interfere with each other (you&#x27;ve been warned!) runAtOnce = map </code></pre> When using `map` functions (which is a lot!) I subconsciously treat it as if it will be executed concurrently, in parallel, in any order. Consider that even an imperative languages like Javascript provide a separate `forEach` function, to prevent &quot;abuses&quot; of `map`. Even Emacs Lisp, not the most highly regarded language, provides separate `mapcar` and `mapc` functions for this reason.<p>With that said, I recognise that there&#x27;s a problem here; but the problem seems to be &#x27;mapping a self-interfering function&#x27;. If we try to make it non-interfering, we see that it&#x27;s due to the use of a shared global value (`stdout`); another code smell! Whilst stdout is append-only, it&#x27;s still mutable, so I&#x27;d try to remove this shared mutable state. Message passing is one alternative, where we can have each call&#x2F;action explicitly take in the handle, then pass it along (either directly, or via some sort of &quot;trampoline&quot;, like an MVar). This way we get the &quot;concurrent from the outside, single-threaded on the inside&quot; behaviour of actor systems like Erlang. In particular, it&#x27;s easy to make sure the handle <i>only</i> get passed along when we&#x27;re &#x27;finished&#x27; with it (i.e. we&#x27;ve written a complete &quot;block&quot; of output).
divs1210大约 7 年前
Thread-unsafe `println` is one of Clojure&#x27;s quirks too!
评论 #17045862 未加载
heavenlyhash大约 7 年前
I&#x27;m kind of surprised to hear that writing to stdout is a source of concurrency problems in a language that&#x27;s considered to be functional.<p>Surely if you can pass your IO handles to all functions that need them, you can decide on a mutexing&#x2F;buffering strategy at the top of your program, wrap the standard IO interface with a delegate that does so, and pass it on. Then, for all libraries called thereafter to use it consistently isn&#x27;t just a no-brainer, it&#x27;s an outright given, isn&#x27;t it? There&#x27;s no <i>global</i> (impure, non-functional) handle to stdout, is there?
评论 #17047751 未加载
评论 #17047831 未加载
clord大约 7 年前
Use an STM channel or some other lock and put your messages for the shared resource (the terminal ui) through that channel. There’s no way to automatically figure out what granularity the programmer expects from the output so make them specify. Haskell makes specifying that staggeringly easy compared to other languages.
bitL大约 7 年前
How can you get a performant language if your I&#x2F;O granularity is 1 character? :-O<p>EDIT: this is an honest question, I was shocked to read what was in the article.
评论 #17049588 未加载
bru大约 7 年前
Title is missing a (2016).