# README

> This is the Simplified Chinese translation of [*mostly-adequate-guide*](https://github.com/DrBoolean/mostly-adequate-guide), thank Professor [Franklin Risby](https://github.com/DrBoolean) for his great work!

## 关于本书

这本书的主题是函数范式（functional paradigm），我们将使用 JavaScript 这门世界上最流行的函数式编程语言来讲述这一主题。有人可能会觉得选择 JavaScript 并不明智，因为当前的主流观点认为它是一门命令式（imperative）的语言，并不适合用来讲函数式。但我认为，这是学习函数式编程的最好方式，因为：

* **你很有可能在日常工作中使用它**

  这让你有机会在实际的编程过程中学以致用，而不是在空闲时间用一门深奥的函数式编程语言做一些玩具性质的项目。
* **你不必从头学起就能开始编写程序**

  在纯函数式编程语言中，你必须使用 monad 才能打印变量或者读取 DOM 节点。JavaScript 则简单得多，可以作弊走捷径，因为毕竟我们的目的是学写纯函数式代码。JavaScript 也更容易入门，因为它是一门混合范式的语言，你随时可以在感觉吃力的时候回退到原有的编程习惯上去。
* **这门语言完全有能力书写高级的函数式代码**

  只需借助一到两个微型类库，JavaScript 就能模拟 Scala 或 Haskell 这类语言的全部特性。虽然面向对象编程（Object-oriented programing）主导着业界，但很明显这种范式在 JavaScript 里非常笨拙，用起来就像在高速公路上露营或者穿着橡胶套鞋跳踢踏舞一样。我们不得不到处使用 `bind` 以免 `this` 不知不觉地变了，语言里没有类可以用（目前还没有），我们还发明了各种变通方法来应对忘记调用 `new` 关键字后的怪异行为，私有成员只能通过闭包（closure）才能实现，等等。对大多数人来说，函数式编程看起来更加自然。

以上说明，强类型的函数式语言毫无疑问将会成为本书所示范式的最佳试验场。JavaScript 是我们学习这种范式的一种手段，将它应用于什么地方则完全取决于你自己。幸运的是，所有的接口都是数学的，因而也是普适的。最终你会发现你习惯了 swiftz、scalaz、haskell 和 purescript，以及其他各种数学偏向的语言。

#### Gitbook (更好的阅读体验)

* [在线阅读](https://llh911001.gitbooks.io/mostly-adequate-guide-chinese/content/)
* [下载EPUB](https://www.gitbook.com/download/epub/book/llh911001/mostly-adequate-guide-chinese)
* [下载Mobi (Kindle)](https://www.gitbook.com/download/mobi/book/llh911001/mostly-adequate-guide-chinese)

## 目录

### 第 1 部分

* [第 1 章: 我们在做什么？](/mostly-adequate-guide-chinese/ch1.md)
  * [介绍](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDDkTAuKOSH355C#介绍)
  * [一个简单例子](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDDkTAuKOSH355C#一个简单例子)
* [第 2 章: 一等公民的函数](/mostly-adequate-guide-chinese/ch2.md)
  * [快速概览](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDGb8Es_h6WFxa7#快速概览)
  * [为何钟爱一等公民](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDGb8Es_h6WFxa7#为何钟爱一等公民)
* [第 3 章: 纯函数的好处](/mostly-adequate-guide-chinese/ch3.md)
  * [再次强调“纯”](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDJQLNYzJpYILes#再次强调“纯”)
  * [副作用可能包括...](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDJQLNYzJpYILes#副作用可能包括)
  * [八年级数学](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDJQLNYzJpYILes#八年级数学)
  * [追求“纯”的理由](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDJQLNYzJpYILes#追求“纯”的理由)
  * [总结](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDJQLNYzJpYILes#总结)
* [第 4 章: 柯里化（curry）](/mostly-adequate-guide-chinese/ch4.md)
  * [不可或缺的 curry](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDP38GjfxFSRu8G#不可或缺的-curry)
  * [不仅仅是双关语／咖喱](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDP38GjfxFSRu8G#不仅仅是双关语咖喱)
  * [总结](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDP38GjfxFSRu8G#总结)
* [第 5 章: 代码组合（compose）](/mostly-adequate-guide-chinese/ch5.md)
  * [函数饲养](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDTslAEcot3ytwW#函数饲养)
  * [pointfree](/mostly-adequate-guide-chinese/ch5.md#pointfree)
  * [debug](/mostly-adequate-guide-chinese/ch5.md#debug)
  * [范畴学](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDTslAEcot3ytwW#范畴学)
  * [总结](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDTslAEcot3ytwW#总结)
* [第 6章: 示例应用](/mostly-adequate-guide-chinese/ch6.md)
  * [声明式代码](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDZGzl3apnReILI#声明式代码)
  * [一个函数式的 flickr](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDZGzl3apnReILI#一个函数式的-flickr)
  * [有原则的重构](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDZGzl3apnReILI#有原则的重构)
  * [总结](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDZGzl3apnReILI#总结)

### 第 2 部分

* [第 7 章: Hindley-Milner 类型签名](/mostly-adequate-guide-chinese/ch7.md)
  * [初识类型](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDdluzlLm2cYlNb#初识类型)
  * [神秘的传奇故事](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDdluzlLm2cYlNb#神秘的传奇故事)
  * [缩小可能性范围](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDdluzlLm2cYlNb#缩小可能性范围)
  * [自由定理](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDdluzlLm2cYlNb#自由定理)
  * [总结](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDdluzlLm2cYlNb#总结)
* [第 8 章: 特百惠](/mostly-adequate-guide-chinese/ch8.md)
  * [强大的容器](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDjeKxWItrlsblk#强大的容器)
  * [第一个 functor](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDjeKxWItrlsblk#第一个-functor)
  * [薛定谔的 Maybe](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDjeKxWItrlsblk#薛定谔的-maybe)
  * [“纯”错误处理](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDjeKxWItrlsblk#“纯”错误处理)
  * [王老先生有作用...](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDjeKxWItrlsblk#王老先生有作用)
  * [异步任务](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDjeKxWItrlsblk#异步任务)
  * [一点理论](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDjeKxWItrlsblk#一点理论)
  * [总结](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDjeKxWItrlsblk#总结)
* [第 9 章: Monad](/mostly-adequate-guide-chinese/ch9.md)
  * [pointed functor](/mostly-adequate-guide-chinese/ch9.md#pointed-functor)
  * [混合比喻](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDsP9qaaUuc9sUp#混合比喻)
  * [chain 函数](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDsP9qaaUuc9sUp#chain-函数)
  * [理论](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDsP9qaaUuc9sUp#理论)
  * [总结](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDsP9qaaUuc9sUp#总结)
* [第 10 章: Applicative Functor](/mostly-adequate-guide-chinese/ch10.md)
  * [应用 applicative functor](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDyu7RChHr5SrHt#应用-applicative-functor)
  * [瓶中之船](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDyu7RChHr5SrHt#瓶中之船)
  * [协调与激励](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDyu7RChHr5SrHt#协调与激励)
  * [lift](/mostly-adequate-guide-chinese/ch10.md#lift)
  * [免费开瓶器](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDyu7RChHr5SrHt#免费开瓶器)
  * [定律](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDyu7RChHr5SrHt#定律)
  * [总结](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-M4muCDyu7RChHr5SrHt#总结)
* [第 11 章: 再转换一次，就很自然](/mostly-adequate-guide-chinese/ch11.md)
  * [令人生厌的嵌套](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxeYnxlU6D55cAoP#令人生厌的嵌套)
  * [一场情景喜剧](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxeYnxlU6D55cAoP#一场情景喜剧)
  * [全都很自然](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxeYnxlU6D55cAoP#全都很自然)
  * [有原则的类型转换](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxeYnxlU6D55cAoP#有原则的类型转换)
  * [方法狂](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxeYnxlU6D55cAoP#方法狂)
  * [同构的 JavaScript](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxeYnxlU6D55cAoP#同构的-javascript)
  * [更加宽泛的定义](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxeYnxlU6D55cAoP#更加宽泛的定义)
  * [实现单层嵌套的方法](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxeYnxlU6D55cAoP#实现单层嵌套的方法)
  * [总结](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxeYnxlU6D55cAoP#总结)
* [第 12 章: 遍历](/mostly-adequate-guide-chinese/ch12.md)
  * [类型与类型](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxehr_fxgckvOoFF#类型与类型)
  * [类型风水](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxehr_fxgckvOoFF#类型风水)
  * [作用组合](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxehr_fxgckvOoFF#作用组合)
  * [类型的华尔兹](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxehr_fxgckvOoFF#类型的华尔兹)
  * [定律](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxehr_fxgckvOoFF#定律)
  * [同一律](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxehr_fxgckvOoFF#同一律-identity)
  * [组合](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxehr_fxgckvOoFF#组合-composition)
  * [自然](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxehr_fxgckvOoFF#自然-naturality)
  * [总结](https://llh911001.gitbook.io/mostly-adequate-guide-chinese/pages/-MdHlxehr_fxgckvOoFF#总结)
* [第 13 章：集大成者的 Monoid](https://github.com/llh911001/mostly-adequate-guide-chinese/blob/master/ch13.md)
  * [狂野的 Combination](https://github.com/llh911001/mostly-adequate-guide-chinese/blob/master/ch13.md#狂野的-combination)
  * [将加法抽象化](https://github.com/llh911001/mostly-adequate-guide-chinese/blob/master/ch13.md#将加法抽象化)
  * [我喜爱的 functor 都是 semigroup](https://github.com/llh911001/mostly-adequate-guide-chinese/blob/master/ch13.md#我喜爱的-functor-都是-semigroup)
  * [空的 Monoid](https://github.com/llh911001/mostly-adequate-guide-chinese/blob/master/ch13.md#空的-monoid)
  * [把房子折叠起来](https://github.com/llh911001/mostly-adequate-guide-chinese/blob/master/ch13.md#把房子折叠起来)
  * [不太算 Monoid](https://github.com/llh911001/mostly-adequate-guide-chinese/blob/master/ch13.md#不太算-monoid)
  * [大一统理论](https://github.com/llh911001/mostly-adequate-guide-chinese/blob/master/ch13.md#大一统理论)
  * [群论还是范畴论](https://github.com/llh911001/mostly-adequate-guide-chinese/blob/master/ch13.md#群论还是范畴论)
  * [总结](https://github.com/llh911001/mostly-adequate-guide-chinese/blob/master/ch13.md#总结)

## 未来计划

* 第 1 部分是基础知识。这是初版草稿，所以我会及时更正发现的的错误。欢迎提供帮助！
* 第 2 部分讲述类型类（type class），比如 functor 和 monad，最后会讲到到 traversable。我希望能塞进来一些 monad transformer 相关的知识，再写一个纯函数的应用。
* 第 3 部分将开始游走于编程实践与学院学究之间。我们将学习 comonad、f-algebra、free monad、yoneda 以及其他一些范畴学概念。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://llh911001.gitbook.io/mostly-adequate-guide-chinese/readme.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
