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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Haskell vs Clojure syntax

10 点作者 mrhonza超过 12 年前

9 条评论

fusiongyro超过 12 年前
&#62; ( * ) &#60;$&#62; Just 2 &#60; * &#62; Just 8<p>I would have written "Just 16."<p>&#62; Nothing &#62;&#62;= \x -&#62; return (x * 10)<p>I would have written "Nothing." Actually, that about sums it up.<p><i>Edit</i>: just to expand on the above with some commentary, his examples are all basically as if he saw a salad in a bag, decided he wanted a salad, and proceeded to buy all the ingredients from separate bags, stick them in one big bag, open them all from inside the other bag and mix them together. In practice, you just don't need to do things this way.<p>The first example is treating Maybe as an applicative functor. In practice, when someone does this, they don't use a bare operator like ( * ). Suppose I want to read in an integer from the user. Which is easier to understand?<p><pre><code> x &#60;- getLine &#62;&#62;= return . read </code></pre> or<p><pre><code> x &#60;- read &#60;$&#62; getLine </code></pre> This is the usual way &#60;$&#62; is used, not his way. You could even get some mileage out of using monads with the do notation, by doing something more like:<p><pre><code> x &#60;- getLine return $ read x </code></pre> Same with the next example:<p><pre><code> x &#60;- Just 2 y &#60;- Just 8 return $ x * y </code></pre> but there's no intrinsic reason to instead write that as he did.<p>Similarly, his second example reads much better when you consider the do notation:<p><pre><code> x &#60;- Nothing return $ x * 10 </code></pre> In fact, even using the syntax he proposes on the other line produces a more readable example:<p><pre><code> Nothing &#62;&#62;= return . (*10) </code></pre> If you don't understand what's going on with his second example, you should brush up on monads. You don't need to understand applicative functors to get things done, but they do make life better when used in moderation.
crntaylor超过 12 年前
It would have been more compelling if the author exhibited two code snippets that do the same thing.<p>In the Clojure example, he adds two numbers together, defines a function that modifies a string by prepending "Hello " and defines a constant.<p>In the Haskell example he overloads the `pure` and &#60;*&#62; functions to work on the 'Maybe' type, allowing arbitrary functions to be lifted into 'Maybe' to allow automatic propagation of failure.
评论 #5210626 未加载
评论 #5209588 未加载
chc超过 12 年前
This has to be the shallowest possible analysis you could have given this issue. No explanation of the tradeoffs or exploration of why they took the routes they did. Just, "Haskell has, like, syntax man. Syntax is hard."<p>Additionally, the explanation of Clojure syntax is woefully incomplete — going by this article, {:age 1} and #inst "@2012-02-12T01:02:03.456" aren't valid Clojure. In reality, Clojure is very syntax-heavy for a Lisp, and most Lisps still have more complicated syntax than the simplistic "Things go between parentheses, the first of which is evaluated as a function and the rest of which are arguments" — look at just about any macro definition in any Lisp to see a fair bit of syntax beyond parentheses.
评论 #5209601 未加载
sitharus超过 12 年前
That's hardly a fair comparison, the equivalent Haskell to the Clojure example is fairly similar, though my Haskell is a bit rusty at this point.<p><pre><code> sum = 1 + 2 greet name = "Hello " ++ name usercount = 34 </code></pre> I'm not 100% sure what the Haskell example is trying to accomplish though.
thirsteh超过 12 年前
What a terrible post. Those two snippets aren't even slightly related. It's like the author is comparing a basic "Hello World" in C to some entry from the obfuscated C competition.
Mr_T_超过 12 年前
Clojure has [] and {} and #{} and '() and #() and : and ^ and @ and Foo. and .foo and -&#62;, ... you still have to learn them to understand Clojure code.
rmangi超过 12 年前
I don't understand why such sophomoric drivel gets posted so often to hacker news.
rossjudson超过 12 年前
With Haskell you get to learn the crazy syntax of the standard. With Clojure you get to learn the crazy syntax of whatever program you're looking at.
评论 #5209578 未加载
评论 #5209564 未加载
评论 #5209566 未加载
评论 #5209565 未加载
lucian1900超过 12 年前
What? Haskell barely has any syntax as well. Slightly more than lisps, but nowhere near to C family languages.