Functional programming in Scala:
Gespeichert in:
Hauptverfasser: | , |
---|---|
Format: | Buch |
Sprache: | English |
Veröffentlicht: |
Shelter Island, NY
Manning
2015
|
Schlagworte: | |
Online-Zugang: | Inhaltsverzeichnis |
Beschreibung: | Hier auch später erschienene, unveränderte Nachdrucke |
Beschreibung: | XX, 300 S. graph. Darst. |
ISBN: | 1617290653 9781617290657 |
Internformat
MARC
LEADER | 00000nam a2200000 c 4500 | ||
---|---|---|---|
001 | BV041707242 | ||
003 | DE-604 | ||
005 | 20180514 | ||
007 | t | ||
008 | 140225s2015 d||| |||| 00||| eng d | ||
020 | |a 1617290653 |9 1-617290-65-3 | ||
020 | |a 9781617290657 |9 978-1-617290-65-7 | ||
035 | |a (OCoLC)892624908 | ||
035 | |a (DE-599)BVBBV041707242 | ||
040 | |a DE-604 |b ger |e rakwb | ||
041 | 0 | |a eng | |
049 | |a DE-91G |a DE-573 |a DE-11 |a DE-B768 |a DE-706 |a DE-20 |a DE-523 | ||
082 | 0 | |a 005.13/3 |2 23 | |
084 | |a ST 250 |0 (DE-625)143626: |2 rvk | ||
084 | |a ST 326 |0 (DE-625)143662: |2 rvk | ||
084 | |a DAT 368f |2 stub | ||
084 | |a DAT 544f |2 stub | ||
100 | 1 | |a Chiusano, Paul |e Verfasser |0 (DE-588)1076887651 |4 aut | |
245 | 1 | 0 | |a Functional programming in Scala |c Paul Chiusano ; Rúnar Bjarnason |
264 | 1 | |a Shelter Island, NY |b Manning |c 2015 | |
300 | |a XX, 300 S. |b graph. Darst. | ||
336 | |b txt |2 rdacontent | ||
337 | |b n |2 rdamedia | ||
338 | |b nc |2 rdacarrier | ||
500 | |a Hier auch später erschienene, unveränderte Nachdrucke | ||
650 | 0 | 7 | |a Scala |g Programmiersprache |0 (DE-588)7658965-1 |2 gnd |9 rswk-swf |
689 | 0 | 0 | |a Scala |g Programmiersprache |0 (DE-588)7658965-1 |D s |
689 | 0 | |5 DE-604 | |
700 | 1 | |a Bjarnason, Rúnar |e Verfasser |0 (DE-588)1076887848 |4 aut | |
856 | 4 | 2 | |m HEBIS Datenaustausch |q application/pdf |u http://bvbr.bib-bvb.de:8991/F?func=service&doc_library=BVB01&local_base=BVB01&doc_number=027154513&sequence=000001&line_number=0001&func_code=DB_RECORDS&service_type=MEDIA |3 Inhaltsverzeichnis |
999 | |a oai:aleph.bib-bvb.de:BVB01-027154513 |
Datensatz im Suchindex
_version_ | 1804151977727229952 |
---|---|
adam_text | Functional Programming
in Scala
PAUL CHIUSANO
RÜNAR BJARNASON
ii
MANNING
Shelter Island
Part 1
Part 2
Part 3
Part 4
brief contents
Introm-c:vk i* «? ••• **1
1 ■ What is functional programming? 3
2 ■ Getting started with functional programming in Scala 14
3 ■ Functional data structures 29
4 ■ Handling errors without exceptions 48
5 ■ Strictness and laziness 64
6 ■ Purely functional state 78
Functional ulsh a » : -■ ■
7 ■ Purely functional parallelism 95
8 ■ Property-based testing 124
9 ■ Parser combinators 146
COMMONHUTCM KrGs ’
10 ■ Monoids 175
11 ■ Monads 187
12 ■ Applicative and traversable functors 205
Effects ni l o
13 ■ External effects and I/O 229
14 ■ Local effects and mutable state 254
15 ■ Stream processing and incremental I/O 268
contents
foreword, xiii
preface xv
acknowledgments xvi
about this book xvii
Part 1 Introm otion to ivNcmoNU programming 1
What is fimctional programming? 3
:11 The benefits of FP: a simple example 4
A program with side effects 4 ■ A functional solution: removing the
side effects 6
1 2 Exactly what is a (pure) function? 9
1 3 Referential transparency, purity, and the
substitution model 10
1 4 Summary 13
} Getting started with functional programming in Scala 14
2 1 Introducing Scala the language: an example 15
2 2 Running our program 17
2 3 Modules, objects, and namespaces 18
2 4 Higher-order functions: passing functions to
functions 19
A short detour: writing loops functionally 20 • Writing our
first higher-order function 21
VII
CONTENTS
2 5 Polymorphic functions: abstracting over types 22
An example of a polymorphic function 23 ■ Calling HOFs with
anonymous functions 24
2 6 Following types to implementations 25
2 7 Summary 28
Functional data structures 29
3 1 Defining functional data structures 29
3 2 Pattern matching 32
3 3 Data sharing in functional data structures 35
The efficiency of data sharing 36 ■ Improving type inference
for higher-order functions 37
3 4 Recursion over lists and generalizing to higher-order
functions 38
More functions for working with lists 41 ■ Loss of efficiency
when assembling list functions from simpler components 44
3 5 Trees 44
3 6 Summary 47
Handling errors without exceptions 48
4 1 The good and bad aspects of exceptions 48
4 2 Possible alternatives to exceptions 50
4 3 The Option data type 52
Usage patterns for Option 53 ■ Option composition, lifting,
and wrapping exception-oriented APIs 56
4 4 The Either data type 60
4 5 Summary 63
Strictness and laziness 64
5 1 Strict and non-strict functions 65
5 2 An extended example: lazy lists 68
Memoizing streams and avoiding recomputation 69 ■ Helper
functions for inspecting streams 69
5 3 Separating program description from evaluation 70
5 4 Infinite streams and corecursion 73
5 5 Summary 77
CONTENTS
IX
Purely functional state 78
6 1 Generating random numbers using side effects 78
6 2 Purely functional random number generation 80
6 3 Making stateful APIs pure 81
64A better API for state actions 84
Combining state actions _ 85 ■ Nesting state actions 86
65A general state action data type 87
6 6 Purely functional imperative programming 88
6 7 Summary 91
Part 2 Functional design and combinator libraries ,93
Purely functional parallelism 95
*71 Choosing data types and functions 96
A data type for parallel computations 97 ■ Combining parallel
computations 100 ■ Explicit forking 102
7 2 Picking a representation 104
7 3 Refining the API 105
7 4 The algebra of an API 110
The law of mapping 110 ■ The law of forking 112
Breaking the law: a subtle bug 113 ■ A fully non-blocking
Par implementation using actors 115
7 5 Refining combinators to their most general form 120
7 6 Summary 123
Property-based testing 124
” 81A brief tour of property-based testing 124
8 2 Choosing data types and functions 127
Initial snippets of an API 127 ■ The meaning and API of
properties 128 ■ The meaning and API of generators 130
Generators that depend on generated values 131 • Refining the
Prop data type 132
8 3 Test case minimization 134
8 4 Using the library and improving its usability 136
Some simple examples 137• Writing a test suite for parallel
computations 138
8 5 Testing higher-order functions and future directions 142
X
CONTENTS
8 6 The laws of generators 144
8 7 Summary 144
Parser combinators 146
9 1 Designing an algebra, first 147
92A possible algebra 152
Slicing and nonempty repetition 154
9 3 Handling context sensitivity 156
9 4 Writing aJSON parser 158
The JSON format 158 ■ AJSON parser 159
9 5 Error reporting 160
A possible design 161 ■ Error nesting 162
Controlling branching and backtracking 163
9 6 Implementing the algebra 165
One possible implementation 166 ■ Sequencing parsers 166
Labeling parsers 167 • Failover and backtracking 168
Context-sensitive parsing 169
9 7 Summary 171
Fart 3 Common structures in functional design 173
Monoids 175
10 1 What is a monoid? 175
10 2 Folding lists with monoids 178
10 3 Associativity and parallelism 179
10 4 Example: Parallel parsing 181
10 5 Foldable data structures 183
10 6 Composing monoids 184
Assembling more complex monoids 185 ■ Using composed
monoids to fuse traversals 186
10 7 Summary 186
Monads 187
11 1 Functors: generalizing the map function 187
Functor laws 189
CONTENTS
XI
11 2
11 3
11 4
11 5
11 6
12
Monads: generalizing the flatMap and unit functions 190
The Monad trait 191
Monadic combinators 193
Monad laws 194
The associative law 194 ■ Proving the associative law for a specific
monad 196 ■ The identity laws 197
Just what is a monad? 198
The identity monad 199 ■ The State monad and partial type
application 200
Summary 204
205
Applicative and traversable functors
12 1 Generalizing monads 205
The Applicative trait 206
The difference between monads and applicative
functors 208
The Option applicative versus the Option monad 209
The Parser applicative versus the Parser monad 210
The advantages of applicative functors 211
Not all applicative functors are monads 211
The applicative laws 214
Left and right identity 214 ■ Associativity 215
Naturality of product 216
Traversable functors 218
Uses of Traverse 219
From monoids to applicative functors 220 ■ Traversals with
State 221 ■ Combining traversable structures 223 • Traversal
fusion 224 • Nested traversals 224 ■ Monad composition 225
12 8 Summary 226
12 2
12 3
12 4
12 5
12 6
12 7
Part 4 Effects am : I (
T J External effects and I/O 229
* 13 1 Factoring effects 229
227
CONTENTS
xii
13 2 A simple IO type 231
Handling input effects 232 ■ Benefits and drawbacks of
the simple 10 type 235
13 3 Avoiding the StackOverflowError 237
Reifying control flow as data constructors 237
Trampolining: a general solution to stack overflow 239
13 4 A more nuanced IO type 241
Reasonably priced monads 242 ■ A monad that supports only
console I/O 243 ■ Pure interpreters 246
13 5 Non-blocking and asynchronous I/O 247
13 6 A general-purpose IO type 250
The main program at the end of the universe 250
13 7 Why the IO type is insufficient for streaming I/O 251
13 8 Summary 253
Local effects and mutable state 254
14 1 Purely functional mutable state 254
14 2 A data type to enforce scoping of side effects 256
A little language for scoped mutation 256 ■ An algebra of
mutable references 258 ■ Running mutable state actions 259
Mutable arrays 262 • A purely functional in-place quicksort 263
14 3 Purity is contextual 264
What counts as a side effect ? 266
14 4 Summary 267
Stream processing and incremental I/O 268
15 1 Problems with imperative I/O: an example 268
15 2 Simple stream transducers 271
Creating processes 272 ■ Composing and appending
processes 275 • Processing files 278
15 3 An extensible process type 278
Sources 281 ■ Ensuring resource safety 283 ■ Single-input
processes 285 • Multiple input streams 287 • Sinks 290
Effectful channels 291 ■ Dynamic resource allocation 291
15 4 Applications 292
15 5 Summary 293
|
any_adam_object | 1 |
author | Chiusano, Paul Bjarnason, Rúnar |
author_GND | (DE-588)1076887651 (DE-588)1076887848 |
author_facet | Chiusano, Paul Bjarnason, Rúnar |
author_role | aut aut |
author_sort | Chiusano, Paul |
author_variant | p c pc r b rb |
building | Verbundindex |
bvnumber | BV041707242 |
classification_rvk | ST 250 ST 326 |
classification_tum | DAT 368f DAT 544f |
ctrlnum | (OCoLC)892624908 (DE-599)BVBBV041707242 |
dewey-full | 005.13/3 |
dewey-hundreds | 000 - Computer science, information, general works |
dewey-ones | 005 - Computer programming, programs, data, security |
dewey-raw | 005.13/3 |
dewey-search | 005.13/3 |
dewey-sort | 15.13 13 |
dewey-tens | 000 - Computer science, information, general works |
discipline | Informatik |
format | Book |
fullrecord | <?xml version="1.0" encoding="UTF-8"?><collection xmlns="http://www.loc.gov/MARC21/slim"><record><leader>01571nam a2200397 c 4500</leader><controlfield tag="001">BV041707242</controlfield><controlfield tag="003">DE-604</controlfield><controlfield tag="005">20180514 </controlfield><controlfield tag="007">t</controlfield><controlfield tag="008">140225s2015 d||| |||| 00||| eng d</controlfield><datafield tag="020" ind1=" " ind2=" "><subfield code="a">1617290653</subfield><subfield code="9">1-617290-65-3</subfield></datafield><datafield tag="020" ind1=" " ind2=" "><subfield code="a">9781617290657</subfield><subfield code="9">978-1-617290-65-7</subfield></datafield><datafield tag="035" ind1=" " ind2=" "><subfield code="a">(OCoLC)892624908</subfield></datafield><datafield tag="035" ind1=" " ind2=" "><subfield code="a">(DE-599)BVBBV041707242</subfield></datafield><datafield tag="040" ind1=" " ind2=" "><subfield code="a">DE-604</subfield><subfield code="b">ger</subfield><subfield code="e">rakwb</subfield></datafield><datafield tag="041" ind1="0" ind2=" "><subfield code="a">eng</subfield></datafield><datafield tag="049" ind1=" " ind2=" "><subfield code="a">DE-91G</subfield><subfield code="a">DE-573</subfield><subfield code="a">DE-11</subfield><subfield code="a">DE-B768</subfield><subfield code="a">DE-706</subfield><subfield code="a">DE-20</subfield><subfield code="a">DE-523</subfield></datafield><datafield tag="082" ind1="0" ind2=" "><subfield code="a">005.13/3</subfield><subfield code="2">23</subfield></datafield><datafield tag="084" ind1=" " ind2=" "><subfield code="a">ST 250</subfield><subfield code="0">(DE-625)143626:</subfield><subfield code="2">rvk</subfield></datafield><datafield tag="084" ind1=" " ind2=" "><subfield code="a">ST 326</subfield><subfield code="0">(DE-625)143662:</subfield><subfield code="2">rvk</subfield></datafield><datafield tag="084" ind1=" " ind2=" "><subfield code="a">DAT 368f</subfield><subfield code="2">stub</subfield></datafield><datafield tag="084" ind1=" " ind2=" "><subfield code="a">DAT 544f</subfield><subfield code="2">stub</subfield></datafield><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Chiusano, Paul</subfield><subfield code="e">Verfasser</subfield><subfield code="0">(DE-588)1076887651</subfield><subfield code="4">aut</subfield></datafield><datafield tag="245" ind1="1" ind2="0"><subfield code="a">Functional programming in Scala</subfield><subfield code="c">Paul Chiusano ; Rúnar Bjarnason</subfield></datafield><datafield tag="264" ind1=" " ind2="1"><subfield code="a">Shelter Island, NY</subfield><subfield code="b">Manning</subfield><subfield code="c">2015</subfield></datafield><datafield tag="300" ind1=" " ind2=" "><subfield code="a">XX, 300 S.</subfield><subfield code="b">graph. Darst.</subfield></datafield><datafield tag="336" ind1=" " ind2=" "><subfield code="b">txt</subfield><subfield code="2">rdacontent</subfield></datafield><datafield tag="337" ind1=" " ind2=" "><subfield code="b">n</subfield><subfield code="2">rdamedia</subfield></datafield><datafield tag="338" ind1=" " ind2=" "><subfield code="b">nc</subfield><subfield code="2">rdacarrier</subfield></datafield><datafield tag="500" ind1=" " ind2=" "><subfield code="a">Hier auch später erschienene, unveränderte Nachdrucke</subfield></datafield><datafield tag="650" ind1="0" ind2="7"><subfield code="a">Scala</subfield><subfield code="g">Programmiersprache</subfield><subfield code="0">(DE-588)7658965-1</subfield><subfield code="2">gnd</subfield><subfield code="9">rswk-swf</subfield></datafield><datafield tag="689" ind1="0" ind2="0"><subfield code="a">Scala</subfield><subfield code="g">Programmiersprache</subfield><subfield code="0">(DE-588)7658965-1</subfield><subfield code="D">s</subfield></datafield><datafield tag="689" ind1="0" ind2=" "><subfield code="5">DE-604</subfield></datafield><datafield tag="700" ind1="1" ind2=" "><subfield code="a">Bjarnason, Rúnar</subfield><subfield code="e">Verfasser</subfield><subfield code="0">(DE-588)1076887848</subfield><subfield code="4">aut</subfield></datafield><datafield tag="856" ind1="4" ind2="2"><subfield code="m">HEBIS Datenaustausch</subfield><subfield code="q">application/pdf</subfield><subfield code="u">http://bvbr.bib-bvb.de:8991/F?func=service&doc_library=BVB01&local_base=BVB01&doc_number=027154513&sequence=000001&line_number=0001&func_code=DB_RECORDS&service_type=MEDIA</subfield><subfield code="3">Inhaltsverzeichnis</subfield></datafield><datafield tag="999" ind1=" " ind2=" "><subfield code="a">oai:aleph.bib-bvb.de:BVB01-027154513</subfield></datafield></record></collection> |
id | DE-604.BV041707242 |
illustrated | Illustrated |
indexdate | 2024-07-10T01:03:23Z |
institution | BVB |
isbn | 1617290653 9781617290657 |
language | English |
oai_aleph_id | oai:aleph.bib-bvb.de:BVB01-027154513 |
oclc_num | 892624908 |
open_access_boolean | |
owner | DE-91G DE-BY-TUM DE-573 DE-11 DE-B768 DE-706 DE-20 DE-523 |
owner_facet | DE-91G DE-BY-TUM DE-573 DE-11 DE-B768 DE-706 DE-20 DE-523 |
physical | XX, 300 S. graph. Darst. |
publishDate | 2015 |
publishDateSearch | 2015 |
publishDateSort | 2015 |
publisher | Manning |
record_format | marc |
spelling | Chiusano, Paul Verfasser (DE-588)1076887651 aut Functional programming in Scala Paul Chiusano ; Rúnar Bjarnason Shelter Island, NY Manning 2015 XX, 300 S. graph. Darst. txt rdacontent n rdamedia nc rdacarrier Hier auch später erschienene, unveränderte Nachdrucke Scala Programmiersprache (DE-588)7658965-1 gnd rswk-swf Scala Programmiersprache (DE-588)7658965-1 s DE-604 Bjarnason, Rúnar Verfasser (DE-588)1076887848 aut HEBIS Datenaustausch application/pdf http://bvbr.bib-bvb.de:8991/F?func=service&doc_library=BVB01&local_base=BVB01&doc_number=027154513&sequence=000001&line_number=0001&func_code=DB_RECORDS&service_type=MEDIA Inhaltsverzeichnis |
spellingShingle | Chiusano, Paul Bjarnason, Rúnar Functional programming in Scala Scala Programmiersprache (DE-588)7658965-1 gnd |
subject_GND | (DE-588)7658965-1 |
title | Functional programming in Scala |
title_auth | Functional programming in Scala |
title_exact_search | Functional programming in Scala |
title_full | Functional programming in Scala Paul Chiusano ; Rúnar Bjarnason |
title_fullStr | Functional programming in Scala Paul Chiusano ; Rúnar Bjarnason |
title_full_unstemmed | Functional programming in Scala Paul Chiusano ; Rúnar Bjarnason |
title_short | Functional programming in Scala |
title_sort | functional programming in scala |
topic | Scala Programmiersprache (DE-588)7658965-1 gnd |
topic_facet | Scala Programmiersprache |
url | http://bvbr.bib-bvb.de:8991/F?func=service&doc_library=BVB01&local_base=BVB01&doc_number=027154513&sequence=000001&line_number=0001&func_code=DB_RECORDS&service_type=MEDIA |
work_keys_str_mv | AT chiusanopaul functionalprogramminginscala AT bjarnasonrunar functionalprogramminginscala |