没有合适的资源?快使用搜索试试~ 我知道了~
首页Functional Programming in Swift
Functional Programming in Swift
5星 · 超过95%的资源 需积分: 9 27 下载量 142 浏览量
更新于2023-03-16
评论
收藏 610KB PDF 举报
This book tries to teach you to think functionally. We believe that Swift has the right language features to teach you how to write functional pro- grams.
资源详情
资源评论
资源推荐
Chris Eidhof, Florian Kugler, and Wouter Swierstra
Contents
1 Introduction 6
Current Status of the Book . . . . . . . . . . . . . . . . . . . 8
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 8
2 Thinking Functionally 10
Example: Battleship . . . . . . . . . . . . . . . . . . . . . . 10
First-Class Functions . . . . . . . . . . . . . . . . . . . . . . 17
Type-Driven Development . . . . . . . . . . . . . . . . . . . . 20
Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3 Wrapping Core Image 22
The Filter Type . . . . . . . . . . . . . . . . . . . . . . . . . 23
Building Filters . . . . . . . . . . . . . . . . . . . . . . . . . 23
Composing Filters . . . . . . . . . . . . . . . . . . . . . . . . 27
Theoretical Background: Currying . . . . . . . . . . . . . . . . 29
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
4 Map, Filter, Reduce 33
Introducing Generics . . . . . . . . . . . . . . . . . . . . . . 33
Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Reduce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Putting It All Together . . . . . . . . . . . . . . . . . . . . . . 43
Generics vs. the Any Type . . . . . . . . . . . . . . . . . . . . 44
Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5 Optionals 48
Case Study: Dictionaries . . . . . . . . . . . . . . . . . . . . 48
Combining Optional Values . . . . . . . . . . . . . . . . . . . 52
Why Optionals? . . . . . . . . . . . . . . . . . . . . . . . . . 57
6 QuickCheck 61
Building QuickCheck . . . . . . . . . . . . . . . . . . . . . . 63
Making Values Smaller . . . . . . . . . . . . . . . . . . . . . 67
Arbitrary Arrays . . . . . . . . . . . . . . . . . . . . . . . . . 70
Using QuickCheck . . . . . . . . . . . . . . . . . . . . . . . . 74
Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
7 The Value of Immutability 76
Variables and References . . . . . . . . . . . . . . . . . . . . 76
Value Types vs. Reference Types . . . . . . . . . . . . . . . . 77
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
8 Enumerations 85
Introducing Enumerations . . . . . . . . . . . . . . . . . . . 85
Associated Values . . . . . . . . . . . . . . . . . . . . . . . 88
Adding Generics . . . . . . . . . . . . . . . . . . . . . . . . 91
Optionals Revisited . . . . . . . . . . . . . . . . . . . . . . . 93
The Algebra of Data Types . . . . . . . . . . . . . . . . . . . . 94
Why Use Enumerations? . . . . . . . . . . . . . . . . . . . . 96
9 Purely Functional Data Structures 97
Binary Search Trees . . . . . . . . . . . . . . . . . . . . . . . 97
Autocompletion Using Tries . . . . . . . . . . . . . . . . . . . 104
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
10 Diagrams 110
Drawing Squares and Circles . . . . . . . . . . . . . . . . . . 110
The Core Data Structures . . . . . . . . . . . . . . . . . . . . 114
Calculating and Drawing . . . . . . . . . . . . . . . . . . . . 117
Creating Views and PDFs . . . . . . . . . . . . . . . . . . . . 121
Extra Combinators . . . . . . . . . . . . . . . . . . . . . . . 122
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
11 Generators and Sequences 127
Generators . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Case Study: Better Shrinking in QuickCheck . . . . . . . . . . 137
Beyond Map and Filter . . . . . . . . . . . . . . . . . . . . . 143
12 Parser Combinators 147
The Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Choice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Convenience Combinators . . . . . . . . . . . . . . . . . . . 159
A Simple Calculator . . . . . . . . . . . . . . . . . . . . . . . 163
13 Case Study: Building a Spreadsheet Application 168
Sample Code . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Parsing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
The GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
14 Functors, Applicative Functors, and Monads 191
Functors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Applicative Functors . . . . . . . . . . . . . . . . . . . . . . 194
The M-Word . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
15 Conclusion 202
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . 202
What is Functional Programming? . . . . . . . . . . . . . . . . 204
Closure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Additional Code 206
Standard Library . . . . . . . . . . . . . . . . . . . . . . . . 206
Chapter 10, Diagrams . . . . . . . . . . . . . . . . . . . . . . 208
Chapter 11, Generators . . . . . . . . . . . . . . . . . . . . . 213
Chapter 12, Parser Combinators . . . . . . . . . . . . . . . . 213
References 218
剩余219页未读,继续阅读
wtf1993
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- 2023年中国辣条食品行业创新及消费需求洞察报告.pptx
- 2023年半导体行业20强品牌.pptx
- 2023年全球电力行业评论.pptx
- 2023年全球网络安全现状-劳动力资源和网络运营的全球发展新态势.pptx
- 毕业设计-基于单片机的液体密度检测系统设计.doc
- 家用清扫机器人设计.doc
- 基于VB+数据库SQL的教师信息管理系统设计与实现 计算机专业设计范文模板参考资料.pdf
- 官塘驿林场林防火(资源监管)“空天地人”四位一体监测系统方案.doc
- 基于专利语义表征的技术预见方法及其应用.docx
- 浅谈电子商务的现状及发展趋势学习总结.doc
- 基于单片机的智能仓库温湿度控制系统 (2).pdf
- 基于SSM框架知识产权管理系统 (2).pdf
- 9年终工作总结新年计划PPT模板.pptx
- Hytera海能达CH04L01 说明书.pdf
- 数据中心运维操作标准及流程.pdf
- 报告模板 -成本分析与报告培训之三.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论2