编程与软件工程github.com
用大白话解释函数式编程术语
Functional programming jargon in plain English
2016 — 2022,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是一个 GitHub 上的开源词汇表,用平实的语言和代码示例解释函数式编程中的常见术语,如 Monad、Functor、柯里化、闭包等。它多次登上 Hacker News 首页,是许多开发者入门函数式编程概念时的参考。
为什么经久不衰:它把晦涩的函数式编程黑话翻译成普通人能懂的说法,多年来一直是初学者快速查阅术语的实用手册。
HN 评论精选
作者认为原项目的定义流于表面,并给出了自己对各术语更本质的一句话解释
这些定义其实没把概念讲透,往往只是给了代码示例。在我看来,真正的要点是:Monoid = 可以拼接在一起的单元;Functor = 运行单输入函数的上下文;Applicative = 多输入函数的上下文;Monad = 顺序依赖操作的上下文;Lifting = 从一个上下文转换到另一个;Sum type = 某物是 A 或 B 或 C;Product type = 记录,某物既是 A 又是 B 又是 C;Partial application = 给函数参数设默认值;Currying = 先传部分参数,返回一个接收剩余参数的函数。上下文则是改变程序如何被解释/执行的编译器信息,比如延迟执行、跨列表运行、重定向 IO 等。
mjburgess查看英文原文
These definitions don't really give you the idea, rather often just code examples.. "The ideas", in my view: Monoid = units that can be joined together Functor = context for running a single-input function Applicative = context for multi-input functions Monad = context for sequence-dependent operations Lifting = converting from one context to another Sum type = something is either A or B or C.. Product type = a record = something is both A and B and C Partial application = defaulting an argument to a function Currying = passing some arguments later = rephrasing a function to return a functions of n-1 arguments when given 1, st. the final function will compute the desired result EDIT: Context = compiler information that changes how the program will be interpreted (, executed, compiled,...) Eg., context = run in the future, run across a list, redirect the i/o, ...
讽刺该项目所谓“平实英语”的定义仍然晦涩难懂
“同态映射只是保持结构的映射。事实上,函子只是范畴之间的同态映射,因为它在映射下保持了原范畴的结构。”——哦,好的,这就是“大白话”。
naillo查看英文原文
"A homomorphism is just a structure preserving map. In fact, a functor is just a homomorphism between categories as it preserves the original category's structure under the mapping." Oh ok. Plain english.
推荐另一本更平易近人的函数式编程入门书
在读 Kyle Simpson 的《Functional Light JavaScript》之前我一直没搞懂函数式编程。这本书写得非常好,普通程序员也能轻松读懂。我虽然不是 FP 大师,但现在主要就用这个范式,甚至把一些思想(比如可组合性)用到了用 var() 写的 CSS 里。书可以在 GitHub 上免费阅读。
pseudosavant查看英文原文
I didn't really understand FP until I read Functional Light JavaScript by getify/Kyle Simpson. It is so well written and approachable by mere mortal coders. I'm not an FP wizard, but it is the coding paradigm I mostly use now. I've even adapted some aspects (e.g. composability) to the CSS I write using `var()`. You can buy the book or read it on GitHub: http://fljsbook.com/ https://github.com/getify/functional-light-js
认为脱离用例的术语列表对新手帮助有限,推荐 Elm 作为更友好的入门途径
这类列表缺乏上下文时容易让人不知所措,因为定义往往聚焦于你不懂用例时无法理解的点。比如“提升”那句对新手就很难懂。Elm 在不使用这些术语的情况下暴露函数式特性、并加以简化,做得很好;虽然因此缺少一些更强大的特性,但配合出色的错误提示,是学函数式编程很好的入口。
Latty查看英文原文
Lists like this tend to be a bit overwhelming without context, because a definition can often seem to focus on things that don't make sense if you don't understand the use case, even if you understand the words. Even if you've read the definition of functor first > Lifting is when you take a value and put it into an object like a functor. If you lift a function into an Applicative Functor then you can make it work on values that are also in that functor. Is a pretty rough sentence for someone not familiar. I think Elm does a pretty good job of exposing functional features without falling into using these terms for them, and by simplifying it all. It does pay for that in terms of missing a lot of the more powerful functional features in the name of keeping it simple, but I do think it makes it a great entry-point to get the basics, especially with how good the errors are, which is very valuable when you are learning. I know it's a controversial language on HN to some extent (I certainly have my own issues with it shakes fist at CSS custom properties issue), but I genuinely think it's a great inroad to functional programming.
历次讨论
同类还值得读
开源应用架构
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编辑精选