没有合适的资源?快使用搜索试试~ 我知道了~
Scala 高级编程及实例
5星 · 超过95%的资源 需积分: 15 58 下载量 51 浏览量
2012-09-29
19:12:12
上传
评论
收藏 867KB PDF 举报
温馨提示
试读
145页
Scala 高级编程及实例, 里面 有很多具体的实例代码, 可以边练边学。
资源推荐
资源详情
资源评论
Scala By Example
DRAFT
May 31, 2009
Martin Odersky
PROGRAMMING METHODS LABORATORY
EPFL
SWITZERLAND
Contents
1 Introduction 1
2 A First Example 3
3 Programming with Actors and Messages 7
4 Expressions and Simple Functions 11
4.1 Expressions And Simple Functions . . . . . . . . . . . . . . . . . . . . . . 11
4.2 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3 Conditional Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.4 Example: Square Roots by Newton’s Method . . . . . . . . . . . . . . . . 15
4.5 Nested Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.6 Tail Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5 First-Class Functions 21
5.1 Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5.2 Currying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.3 Example: Finding Fixed Points of Functions . . . . . . . . . . . . . . . . 25
5.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
5.5 Language Elements Seen So Far . . . . . . . . . . . . . . . . . . . . . . . 28
6 Classes and Objects 31
7 Case Classes and Pattern Matching 43
7.1 Case Classes and Case Objects . . . . . . . . . . . . . . . . . . . . . . . . 46
7.2 Pattern Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
8 Generic Types and Methods 51
8.1 Type Parameter Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
8.2 Variance Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
iv CONTENTS
8.3 Lower Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.4 Least Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.5 Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.6 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
9 Lists 63
9.1 Using Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
9.2 Definition of class List I: First Order Methods . . . . . . . . . . . . . . . 65
9.3 Example: Merge sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
9.4 Definition of class List II: Higher-Order Methods . . . . . . . . . . . . . 70
9.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
10 For-Comprehensions 79
10.1 The N-Queens Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
10.2 Querying with For-Comprehensions . . . . . . . . . . . . . . . . . . . . . 81
10.3 Translation of For-Comprehensions . . . . . . . . . . . . . . . . . . . . . 82
10.4 For-Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
10.5 Generalizing For . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
11 Mutable State 87
11.1 Stateful Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
11.2 Imperative Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . 91
11.3 Extended Example: Discrete Event Simulation . . . . . . . . . . . . . . . 92
11.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
12 Computing with Streams 99
13 Iterators 103
13.1 Iterator Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
13.2 Constructing Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
13.3 Using Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
14 Lazy Values 109
15 Implicit Parameters and Conversions 113
CONTENTS v
16 Hindley/Milner Type Inference 117
17 Abstractions for Concurrency 125
17.1 Signals and Monitors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
17.2 SyncVars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
17.3 Futures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
17.4 Parallel Computations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
17.5 Semaphores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
17.6 Readers/Writers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
17.7 Asynchronous Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
17.8 Synchronous Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
17.9 Workers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
17.10Mailboxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
17.11Actors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
剩余144页未读,继续阅读
资源评论
- ou19902017-02-14英文的...需要下载的注意
- lin_ming2016-11-10mark,好好学习下
- freeluotao2014-09-22不错的资源,值得入门学习一下!
- albert6262016-03-30初学Scala,高级编程还不到。。。还没看,应该不错,谢谢分享
xia5563
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功