1 / 157
文档名称:

Scala By Example [Odersky] 2007 [functional programming].pdf

格式:pdf   页数:157页
下载后只包含 1 个 PDF 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

Scala By Example [Odersky] 2007 [functional programming].pdf

上传人:kuo08092 2015/4/23 文件大小:0 KB

下载得到文件列表

Scala By Example [Odersky] 2007 [functional programming].pdf

相关文档

文档介绍

文档介绍:Scala By Example
DRAFT
December 19, 2007
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
Expressions And Simple Functions . . . . . . . . . . . . . . . . . . . . . . 11
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Conditional Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Example: Square Roots by Newton’s Method . . . . . . . . . . . . . . . . 15
Nested Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Tail Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5 First-Class Functions 21
Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Currying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Example: Finding Fixed Points of Functions . . . . . . . . . . . . . . . . 25
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Language Elements Seen So Far . . . . . . . . . . . . . . . . . . . . . . . 28
6 Classes and Objects 31
7 Case Classes and Pattern Matching 43
Case Classes and Case Objects . . . . . . . . . . . . . . . . . . . . . . . . 46
Pattern Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
8 Generic Types and Methods 51
Type Parameter Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Variance Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
iv CONTENTS
Lower Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Least Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Function