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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Trying Haskell

37 点作者 chegra84大约 14 年前

4 条评论

Peaker大约 14 年前
Haskell's type system can also express interesting things most languages' type systems can't.<p>For example:<p><a href="https://github.com/yairchu/red-black-tree/blob/master/AvlTree.hs" rel="nofollow">https://github.com/yairchu/red-black-tree/blob/master/AvlTre...</a> -- in lines 13..21, an AVLTree type is defined -- with its invariants encoded in the type system. If there's a mistake in these 9 lines, you may get a wrong program. But the nice thing is that if you get just these 9 lines right -- then the hundreds of lines below it that implement an AVL tree <i></i>cannot get the AVL invariants wrong<i></i>.<p>The same is also true for Red Black Trees: <a href="https://github.com/yairchu/red-black-tree/blob/master/RedBlackTree.hs" rel="nofollow">https://github.com/yairchu/red-black-tree/blob/master/RedBla...</a><p>Lines 26..36 inclusive encode the RBTree type such that the invariants are enforced by the type-checker.<p>In case this is unclear: the type-checker enforcing the correctness of the invariants is at <i>compile-time</i>. A running program is a correct program, at least from the invariants' perspective.
评论 #2430437 未加载
评论 #2430387 未加载
评论 #2429818 未加载
评论 #2429758 未加载
Tiomaidh大约 14 年前
"Oh look, Haskell is great! Why? Static typing and concise code and no side effects!"<p>I don't disagree on any particular point, but this is hardly news (on HN, at least), and is rather lacking in substance.
评论 #2429771 未加载
ionfish大约 14 年前
Obligatory comment pointing out that the fabled "quicksort" example in Haskell is not actually quicksort proper since it's not in-place.
评论 #2429904 未加载
评论 #2429582 未加载
评论 #2429443 未加载
评论 #2429632 未加载
pdhborges大约 14 年前
C++ quicksort :|<p><pre><code> #include &#60;algorithm&#62; #include &#60;iterator&#62; #include &#60;functional&#62; using namespace std; template &#60;typename T&#62; void sort(T begin, T end) { if (begin != end) { T middle = partition (begin, end, bind2nd(less&#60;iterator_traits&#60;T&#62;::value_type&#62;(), *begin)); sort (begin, middle); sort (max(begin + 1, middle), end); } } </code></pre> from wikipedia
评论 #2430255 未加载