编程与软件工程willamette.edu
Haskell 程序员的进化(2001)
The Evolution of a Haskell Programmer (2001)
2013 — 2021,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这个页面用同一个阶乘函数,展示了它在 Haskell 中从初学者写法到越来越抽象、古怪的高级写法(如无点风格、Church 编码等)的“进化”,是一篇经典的编程幽默/风格赏析。它既好笑,也把 Haskell 的表达力和学习曲线展现得很清楚。
为什么经久不衰:它经久不衰,是因为用玩笑的方式精准捕捉了 Haskell 社区爱玩、爱抽象、爱多解的文化,今天读来仍能让函数式编程学习者会心一笑。
HN 评论精选
用四个阶段调侃 Haskell 学习过程中从自信到彻底迷惑的转变。
阶段 1:没有 bug,因为有强类型、无副作用、函数式天性。阶段 2:好吧,但那些 bug 是我自己的程序员错误。阶段 3:我承认,我完全不知道自己在干什么。阶段 4:好吧,我甚至看不懂我两年前写的 Haskell 想干什么。那时候的我更聪明。
Gratsby查看英文原文
Phase 1: There are no bugs because strong typing, no side effects, functional nature. Phase 2: OK, but those bugs are my own programmer errors. Phase 3: I admit it, I have no idea what I'm doing. Phase 4: OK, I can't even figure out what the Haskell I did two years ago was even trying to do. I was smarter then.
求解释为什么高度抽象的无点/组合子风格反而比直观的累加器递归更快。
据说这个 [s f g x = f x (g x) 等无点/组合子风格定义] 比这个 [facAcc a 0 = a; facAcc a n = facAcc (n*a) (n-1); fac = facAcc 1] 更快,而且这两个是最快的第一名和第二名。> 有趣的是,这是所有实现中最快的,也许反映了实现中使用的底层图归约机制。有人能再解释一下吗?
infinity0查看英文原文
Apparently this s f g x = f x (g x) k x y = x b f g x = f (g x) c f g x = f x g y f = f (y f) cond p f g x = if p x then f x else g x fac = y (b (cond ((==) 0) (k 1)) (b (s (*)) (c b pred))) is faster than this facAcc a 0 = a facAcc a n = facAcc (n*a) (n-1) fac = facAcc 1 and these are the first and second fastest. > Interestingly, this is the fastest of all of the implementations, perhaps reflecting the underlying graph reduction mechanisms used in the implementation. Could anyone elaborate on this a bit more?
Haskell 的玩心和多解性不只是炫技,而是激发发现与编程乐趣的源泉。
这让我想起 Simon Peyton-Jones 在《A History of Haskell》演讲结尾的一段话:Haskell 很好玩,它足够丰富因而有用,但真正重要的是它是一种 playful 的语言,鼓励人们去玩、去写编程珍珠,把编程当作艺术形式,而玩最终会带来新发现。这种玩心在 #haskell IRC 里很明显:问怎么反转列表会变成讨论 fold,谈 ADT 会让你发现“(datatype-)generic programming”的新含义,甚至有个 bot 能把代码变成 100% pointfree。实践中不必用这些超级泛化/golf 的解法,但知道有很多方法就像爵士即兴里熟悉很多 licks 和音阶,让编程更有趣、更灵活。
siraben查看英文原文
This reminds me of one of the closing remarks of Simon Peyton-Jones in his A History of Haskell talk[0]. "Haskell is great fun, it's rich enough to be useful but the thing that I think is really important about it is that it's a kind of playful language. It encourages people who want to play and so I've given some examples here about the sort of playing that people do embedded domain-specific language and cunning type programs, but it's a language in which is fun to write programming pearls in which people really do start to do bits of programming as an art form, write papers about them and even get them published and I think this is good not just because it's fun but also because play leads in the end to to new discoveries so I think languages that are playful lead onto to learning new things." This playfulness is evident whenever you spend enough time in #haskell in IRC, a question about writing a program to reverse a list ends up in a discussion about folds, talking about ADTs leads you to discover a whole new meaning to "(datatype-)generic programming" and so on, there's even a bot that makes your code 100% pointfree (online version at [1])! In practice, it's not needed to use these super generalized/golfed solutions, but having the knowledge that there's many ways to approach the problem is akin to knowing many licks and scales in Jazz improvisation, makes programming a great deal more fun and flexible. [0] https://youtu.be/3bjXGrycMhQ?t=2624 [1] http://pointfree.io/
Haskell 学习曲线陡峭,术语与概念之间的映射往往需要内行指点。
Haskell 充满伟大思想,但它们藏得很深。对我有效的方法是坐在一个对 Haskell 有热情的研究生旁边:我用英语解释一个概念,他告诉我该用 Google 搜哪个 Haskell 术语。
breck查看英文原文
Haskell is so full of great ideas. But they are well hidden. What worked for me is sitting next to a grad student passionate about Haskell. I would explain a concept in English and he would tell me the Haskell term to Google.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选