Programming in Scala (Lập trình Scala) - Martin Odersky, Lex Spoon, Bill

LI
lienhejb
0 lượt tải
547
0

Đang tạo bản xem trước...

Nội dung tài liệu

Trang 1

A comprehensive step-by-step guide Programming inScala Martin Odersky Lex Spoon artima Bill Venners Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 2

Programming in Scala PrePrint™ Edition Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 3

iii Thank you for purchasing the PrePrint™ Edition of Programming in Scala. A PrePrint™ is a work-in-progress, a book that has not yet been fully written, reviewed, edited, or formatted. We are publishing this book as a PrePrint™ for two main reasons. First, even though this book is not quite finished, the information contained in its pages can already provide value to many readers. Second, we hope to get reports of errata and suggestions for improvement from those readers while we still have time incorporate them into the first printing. As a PrePrint™ customer, you’ll be able to download new PrePrint™ versions from Artima as the book evolves, as well as the final PDF of the book once finished. You’ll have access to the book’s content prior to its print publication, and can participate in its creation by submitting feedback. Please submit by clicking on the Suggest link at the bottom of each page. Thanks for your participation. We hope you find the book useful and enjoyable. Bill Venners President, Artima, Inc. Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 4

Programming in Scala PrePrint™ Edition Martin Odersky, Lex Spoon, Bill Venners artima ARTIMA PRESS MOUNTAIN VIEW, CALIFORNIA Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 5

v Programming in Scala PrePrint™ Edition Version 2 Martin Odersky is the creator of the Scala language and a professor at EPFL in Lausanne, Switzerland. Lex Spoon worked on Scala for two years as a post-doc with Martin Odersky. Bill Venners is president of Artima, Inc. Artima Press is an imprint of Artima, Inc. P.O. Box 390122, Mountain View, California 94039 Copyright © 2007, 2008 Martin Odersky, Lex Spoon, and Bill Venners. All rights reserved. PrePrint™ Edition first published 2007 Version 2 published February 18, 2008 Produced in the United States of America 12 11 10 09 08 2 3 4 5 6 No part of this publication may be reproduced, modified, distributed, stored in a retrieval system, republished, displayed, or performed, for commercial or noncommercial purposes or for compensation of any kind without prior written permission from Artima, Inc. All information and materials in this book are provided "as is" and without warranty of any kind. The term “Artima” and the Artima logo are trademarks or registered trademarks of Artima, Inc. All other company and/or product names may be trademarks or registered trademarks of their owners. Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 6

to Nastaran - M.O. to Fay - L.S. to Siew - B.V. Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 7

Overview Contents viii Preface xvi Acknowledgments xvii Introduction xx 1. A Scalable Language 27 2. First Steps in Scala 47 3. Next Steps in Scala 63 4. Classes and Objects 90 5. Basic Types and Operations 114 6. Functional Objects 136 7. Built-in Control Structures 151 8. Functions and Closures 169 9. Control Abstraction 190 10. Composition and Inheritance 205 11. Traits and Mixins 233 12. Case Classes and Pattern Matching 249 13. Packages and Imports 279 14. Working with Lists 292 15. Collections 322 16. Stateful Objects 342 17. Type Parameterization 362 18. Abstract Members and Properties 379 19. Implicit Conversions and Parameters 396 20. Implementing Lists 413 21. Object Equality 424 22. Working with XML 438 23. Actors and Concurrency 450 24. Extractors 461 25. Objects As Modules 473 26. Annotations 484 27. Combining Scala and Java 490 28. Combinator Parsing 502 Glossary 530 Bibliography 544 About the Authors 546 Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 8

Contents Contents viii Preface xvi Acknowledgments xvii Introduction xx 1 A Scalable Language 27 1.1 A language that grows on you . . . . . . . . . . . . . . . . 28 1.2 What makes Scala scalable? . . . . . . . . . . . . . . . . . 33 1.3 Why Scala? . . . . . . . . . . . . . . . . . . . . . . . . . . 36 1.4 Scala’s roots . . . . . . . . . . . . . . . . . . . . . . . . . . 44 1.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 45 2 First Steps in Scala 47 Step 1. Learn to use the Scala interpreter . . . . . . . . . . . . . . 47 Step 2. Define some variables . . . . . . . . . . . . . . . . . . . . 49 Step 3. Define some functions . . . . . . . . . . . . . . . . . . . 51 Step 4. Write some Scala scripts . . . . . . . . . . . . . . . . . . 55 Step 5. Loop with while, decide with if . . . . . . . . . . . . . . 57 Step 6. Iterate with foreach and for . . . . . . . . . . . . . . . . 59 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 3 Next Steps in Scala 63 Step 7. Understand the importance of vals . . . . . . . . . . . . . 63 Step 8. Parameterize Arrays with types . . . . . . . . . . . . . . 65 Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 9

Contents ix Step 9. Use Lists and Tuples . . . . . . . . . . . . . . . . . . . 69 Step 10. Use Sets and Maps . . . . . . . . . . . . . . . . . . . . . 74 Step 11. Understand classes and singleton objects . . . . . . . . . 79 Step 12. Understand traits and mixins . . . . . . . . . . . . . . . 86 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 4 Classes and Objects 90 4.1 Objects and variables . . . . . . . . . . . . . . . . . . . . . 91 4.2 Mapping to Java . . . . . . . . . . . . . . . . . . . . . . . . 93 4.3 Classes and types . . . . . . . . . . . . . . . . . . . . . . . 96 4.4 Fields and methods . . . . . . . . . . . . . . . . . . . . . . 97 4.5 Class documentation . . . . . . . . . . . . . . . . . . . . . 102 4.6 Variable scope . . . . . . . . . . . . . . . . . . . . . . . . . 104 4.7 Semicolon inference . . . . . . . . . . . . . . . . . . . . . 108 4.8 Singleton objects . . . . . . . . . . . . . . . . . . . . . . . 110 4.9 A Scala application . . . . . . . . . . . . . . . . . . . . . . 111 4.10 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 113 5 Basic Types and Operations 114 5.1 Some basic types . . . . . . . . . . . . . . . . . . . . . . . 115 5.2 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 5.3 Operators are methods . . . . . . . . . . . . . . . . . . . . 121 5.4 Arithmetic operations . . . . . . . . . . . . . . . . . . . . . 125 5.5 Relational and logical operations . . . . . . . . . . . . . . . 126 5.6 Object equality . . . . . . . . . . . . . . . . . . . . . . . . 128 5.7 Bitwise operations . . . . . . . . . . . . . . . . . . . . . . 130 5.8 Operator precedence and associativity . . . . . . . . . . . . 131 5.9 Rich wrappers . . . . . . . . . . . . . . . . . . . . . . . . . 133 5.10 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 134 6 Functional Objects 136 6.1 A class for rational numbers . . . . . . . . . . . . . . . . . 136 6.2 Choosing between val and var . . . . . . . . . . . . . . . . 138 6.3 Class parameters and constructors . . . . . . . . . . . . . . 139 6.4 Multiple constructors . . . . . . . . . . . . . . . . . . . . . 140 6.5 Reimplementing the toString method . . . . . . . . . . . 141 6.6 Private methods and fields . . . . . . . . . . . . . . . . . . 142 Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 10

Contents x 6.7 Self references . . . . . . . . . . . . . . . . . . . . . . . . 143 6.8 Defining operators . . . . . . . . . . . . . . . . . . . . . . 143 6.9 Identifiers in Scala . . . . . . . . . . . . . . . . . . . . . . 145 6.10 Method overloading . . . . . . . . . . . . . . . . . . . . . . 147 6.11 Going further . . . . . . . . . . . . . . . . . . . . . . . . . 148 6.12 A word of caution . . . . . . . . . . . . . . . . . . . . . . . 149 6.13 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 150 7 Built-in Control Structures 151 7.1 If expressions . . . . . . . . . . . . . . . . . . . . . . . . . 152 7.2 While loops . . . . . . . . . . . . . . . . . . . . . . . . . . 154 7.3 For expressions . . . . . . . . . . . . . . . . . . . . . . . . 156 7.4 Try expressions . . . . . . . . . . . . . . . . . . . . . . . . 161 7.5 Match expressions . . . . . . . . . . . . . . . . . . . . . . 164 7.6 Living without break and continue . . . . . . . . . . . . . 166 7.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 168 8 Functions and Closures 169 8.1 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 8.2 Nested functions . . . . . . . . . . . . . . . . . . . . . . . 171 8.3 First-class functions . . . . . . . . . . . . . . . . . . . . . . 172 8.4 Short forms of function literals . . . . . . . . . . . . . . . . 175 8.5 Placeholder syntax . . . . . . . . . . . . . . . . . . . . . . 175 8.6 Partially applied functions . . . . . . . . . . . . . . . . . . 177 8.7 Closures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 8.8 Repeated parameters . . . . . . . . . . . . . . . . . . . . . 184 8.9 Tail recursion . . . . . . . . . . . . . . . . . . . . . . . . . 185 8.10 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 189 9 Control Abstraction 190 9.1 Reducing code duplication . . . . . . . . . . . . . . . . . . 190 9.2 Simplifying client code . . . . . . . . . . . . . . . . . . . . 194 9.3 Currying . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 9.4 Writing new control structures . . . . . . . . . . . . . . . . 198 9.5 By-name parameters . . . . . . . . . . . . . . . . . . . . . 201 9.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 204 Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 11

Contents xi 10 Composition and Inheritance 205 10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . 205 10.2 Abstract classes . . . . . . . . . . . . . . . . . . . . . . . . 206 10.3 The Uniform Access Principle . . . . . . . . . . . . . . . . 207 10.4 Assertions and assumptions . . . . . . . . . . . . . . . . . . 209 10.5 Subclasses . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 10.6 Two name spaces, not four . . . . . . . . . . . . . . . . . . 211 10.7 Class parameter fields . . . . . . . . . . . . . . . . . . . . . 213 10.8 More method implementations . . . . . . . . . . . . . . . . 214 10.9 Private helper methods . . . . . . . . . . . . . . . . . . . . 215 10.10Imperative or functional? . . . . . . . . . . . . . . . . . . . 216 10.11Adding other subclasses . . . . . . . . . . . . . . . . . . . 218 10.12Override modifiers and the fragile base class problem . . . . 219 10.13Factories . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 10.14Putting it all together . . . . . . . . . . . . . . . . . . . . . 222 10.15Scala’s class hierarchy . . . . . . . . . . . . . . . . . . . . 225 10.16Implementing primitives . . . . . . . . . . . . . . . . . . . 229 10.17Bottom types . . . . . . . . . . . . . . . . . . . . . . . . . 231 10.18Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 232 11 Traits and Mixins 233 11.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 11.2 Thin versus thick interfaces . . . . . . . . . . . . . . . . . . 235 11.3 The standard Ordered trait . . . . . . . . . . . . . . . . . . 236 11.4 Traits for modifying interfaces . . . . . . . . . . . . . . . . 238 11.5 Stacking modifications . . . . . . . . . . . . . . . . . . . . 241 11.6 Locking and logging queues . . . . . . . . . . . . . . . . . 242 11.7 Traits versus multiple inheritance . . . . . . . . . . . . . . . 245 11.8 To trait, or not to trait? . . . . . . . . . . . . . . . . . . . . 247 12 Case Classes and Pattern Matching 249 12.1 A simple example . . . . . . . . . . . . . . . . . . . . . . . 249 12.2 Kinds of patterns . . . . . . . . . . . . . . . . . . . . . . . 253 12.3 Pattern guards . . . . . . . . . . . . . . . . . . . . . . . . . 261 12.4 Pattern overlaps . . . . . . . . . . . . . . . . . . . . . . . . 263 12.5 Sealed classes . . . . . . . . . . . . . . . . . . . . . . . . . 264 12.6 The Option type . . . . . . . . . . . . . . . . . . . . . . . 266 Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 12

Contents xii 12.7 Patterns everywhere . . . . . . . . . . . . . . . . . . . . . . 267 12.8 A larger example . . . . . . . . . . . . . . . . . . . . . . . 271 12.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 278 13 Packages and Imports 279 13.1 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 13.2 Imports . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 13.3 Access modifiers . . . . . . . . . . . . . . . . . . . . . . . 286 14 Working with Lists 292 14.1 List literals . . . . . . . . . . . . . . . . . . . . . . . . . . 292 14.2 The List type . . . . . . . . . . . . . . . . . . . . . . . . . 292 14.3 Constructing lists . . . . . . . . . . . . . . . . . . . . . . . 293 14.4 Basic operations on lists . . . . . . . . . . . . . . . . . . . 294 14.5 List patterns . . . . . . . . . . . . . . . . . . . . . . . . . . 295 14.6 Operations on lists Part I: First-order methods . . . . . . . . 297 14.7 Operations on lists Part II: Higher-order methods . . . . . . 307 14.8 Operations on lists Part III: Methods of the List object . . . 315 14.9 Understanding Scala’s type inference algorithm . . . . . . . 318 15 Collections 322 15.1 Overview of the library . . . . . . . . . . . . . . . . . . . . 322 15.2 Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . 324 15.3 Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 15.4 Sets and maps . . . . . . . . . . . . . . . . . . . . . . . . . 331 15.5 Initializing collections . . . . . . . . . . . . . . . . . . . . 335 15.6 Immutable collections . . . . . . . . . . . . . . . . . . . . . 336 15.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 341 16 Stateful Objects 342 16.1 What makes an object stateful? . . . . . . . . . . . . . . . . 342 16.2 Reassignable variables and properties . . . . . . . . . . . . 344 16.3 Case study: discrete event simulation . . . . . . . . . . . . . 347 16.4 A language for digital circuits . . . . . . . . . . . . . . . . 348 16.5 The Simulation API . . . . . . . . . . . . . . . . . . . . . 352 16.6 Circuit Simulation . . . . . . . . . . . . . . . . . . . . . . . 355 16.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 361 Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 13

Contents xiii 17 Type Parameterization 362 17.1 Functional queues . . . . . . . . . . . . . . . . . . . . . . . 362 17.2 Information hiding . . . . . . . . . . . . . . . . . . . . . . 365 17.3 Variance annotations . . . . . . . . . . . . . . . . . . . . . 367 17.4 Lower bounds . . . . . . . . . . . . . . . . . . . . . . . . . 374 17.5 Contravariance . . . . . . . . . . . . . . . . . . . . . . . . 375 17.6 Object-local data . . . . . . . . . . . . . . . . . . . . . . . 376 17.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 378 18 Abstract Members and Properties 379 18.1 Abstract vals . . . . . . . . . . . . . . . . . . . . . . . . . 380 18.2 Abstract vars . . . . . . . . . . . . . . . . . . . . . . . . . 381 18.3 Abstract types . . . . . . . . . . . . . . . . . . . . . . . . 382 18.4 Case study: Currencies . . . . . . . . . . . . . . . . . . . . 385 18.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 395 19 Implicit Conversions and Parameters 396 19.1 Implicit conversions . . . . . . . . . . . . . . . . . . . . . . 396 19.2 The fine print . . . . . . . . . . . . . . . . . . . . . . . . . 399 19.3 Implicit conversion to an expected type . . . . . . . . . . . 403 19.4 Converting the receiver . . . . . . . . . . . . . . . . . . . . 403 19.5 Implicit parameters . . . . . . . . . . . . . . . . . . . . . . 406 19.6 View bounds . . . . . . . . . . . . . . . . . . . . . . . . . 408 19.7 Debugging implicits . . . . . . . . . . . . . . . . . . . . . . 410 20 Implementing Lists 413 20.1 The List class in principle . . . . . . . . . . . . . . . . . . 413 20.2 The ListBuffer class . . . . . . . . . . . . . . . . . . . . 418 20.3 The List class in practice . . . . . . . . . . . . . . . . . . 420 20.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 422 21 Object Equality 424 21.1 Writing an equality method . . . . . . . . . . . . . . . . . . 425 22 Working with XML 438 22.1 Semi-structured data . . . . . . . . . . . . . . . . . . . . . 438 22.2 Creating XML . . . . . . . . . . . . . . . . . . . . . . . . . 439 Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 14

Contents xiv 22.3 Taking XML apart . . . . . . . . . . . . . . . . . . . . . . 442 22.4 Loading and saving . . . . . . . . . . . . . . . . . . . . . . 444 22.5 Pattern matching . . . . . . . . . . . . . . . . . . . . . . . 446 22.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 449 23 Actors and Concurrency 450 23.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 450 23.2 Locks considered harmful . . . . . . . . . . . . . . . . . . . 450 23.3 Actors and message passing . . . . . . . . . . . . . . . . . 451 23.4 Treating native threads as actors . . . . . . . . . . . . . . . 454 23.5 Tips for better actors . . . . . . . . . . . . . . . . . . . . . 455 24 Extractors 461 24.1 An Example . . . . . . . . . . . . . . . . . . . . . . . . . . 461 24.2 Extractors . . . . . . . . . . . . . . . . . . . . . . . . . . . 463 24.3 Patterns with zero or one variables . . . . . . . . . . . . . . 465 24.4 Variable argument extractors . . . . . . . . . . . . . . . . . 467 24.5 Extractors and sequence patterns . . . . . . . . . . . . . . . 469 24.6 Extractors vs Case Classes . . . . . . . . . . . . . . . . . . 470 24.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 472 25 Objects As Modules 473 25.1 A basic database . . . . . . . . . . . . . . . . . . . . . . . 473 25.2 Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . 476 25.3 Splitting modules into traits . . . . . . . . . . . . . . . . . . 478 25.4 Runtime linking . . . . . . . . . . . . . . . . . . . . . . . . 480 25.5 Tracking module instances . . . . . . . . . . . . . . . . . . 481 25.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 483 26 Annotations 484 26.1 Why have annotations? . . . . . . . . . . . . . . . . . . . . 484 26.2 Syntax of annotations . . . . . . . . . . . . . . . . . . . . . 485 26.3 Standard annotations . . . . . . . . . . . . . . . . . . . . . 487 26.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 489 27 Combining Scala and Java 490 27.1 Translation details . . . . . . . . . . . . . . . . . . . . . . . 490 Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 15

Contents xv 27.2 Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . 494 27.3 Existential types . . . . . . . . . . . . . . . . . . . . . . . . 498 27.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 501 28 Combinator Parsing 502 28.1 Example: Arithmetic Expressions . . . . . . . . . . . . . . 503 28.2 Running Your Parser . . . . . . . . . . . . . . . . . . . . . 505 28.3 Another Example: JSON . . . . . . . . . . . . . . . . . . . 507 28.4 Parser Output . . . . . . . . . . . . . . . . . . . . . . . . . 509 28.5 Implementing Combinator Parsers . . . . . . . . . . . . . . 513 28.6 Lexing and Parsing . . . . . . . . . . . . . . . . . . . . . . 522 28.7 Standard Token Parsers . . . . . . . . . . . . . . . . . . . . 523 28.8 Error reporting . . . . . . . . . . . . . . . . . . . . . . . . 524 28.9 Backtracking vs LL(1) . . . . . . . . . . . . . . . . . . . . 526 28.10Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 528 Glossary 530 Bibliography 544 About the Authors 546 Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 16

Preface I’d like to thank you for purchasing the PrePrint™ Edition of Programming in Scala. Even though the book is still somewhat rough, we believe you can already use this book very effectively to learn Scala. We released this PrePrint™ quite early in the book-writing process in part because so little documentation has up to now existed for Scala, but also because we want feedback to help us make the book better. At the bottom of each page is a Suggest link, which will take you to a small web application where you can submit comments about that page. We’ll know which version and page you’re on, so all you need to do is type your comment. At this point we’re interested in feedback on all aspects of the book ex- cept formatting. Please report any misspelled words, typos, or grammar er- rors. Let us know if you find something confusing, and be specific. Point out places where we appear to assume you know something that you don’t. In short, we’re interested in hearing about your reading experience, but please don’t report formatting errors. Formatting is something we plan to fix shortly before we send the book to the printer. At this point, we are aware that some lines are too long, the words are spaced out a bit too much here and there, the figures are surrounded by inconsistently sized white space, etc. Please forgive us for this for the time being, and don’t report such problems. By purchasing Version 2 of Programming in Scala, PrePrint™ Edition, you are entitled to download all updates until we publish the final version of the book. We thank you again for getting in on the ground floor and look forward to your feedback. Bill Venners Sunnyvale, California February 18, 2008 Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 17

Acknowledgments Many people have contributed to this book and to the material it covers. We are grateful to all of them. Scala itself has been a collective effort of many people. The design and the implementation of version 1.0 was helped by Philippe Altherr, Vincent Cremet, Gilles Dubochet, Burak Emir, Stéphane Micheloud, Nikolay Mi- haylov, Michel Schinz, Erik Stenman, and Matthias Zenger. Iulian Dragos, Gilles Dubochet, Philipp Haller, Sean McDirmid, Ingo Maier, and Adriaan Moors joined in the effort to develop the second and current version of the language and tools. Gilad Bracha, Craig Chambers, Erik Ernst, Matthias Felleisen, Shriram Krishnamurti, Gary Leavens, Sebastian Maneth, Erik Meijer, David Pol- lak, Jon Pretty, Klaus Ostermann, Didier Rémy, Vijay Saraswat, Don Syme, Mads Torgersen, Philip Wadler, Jamie Webb, and John Williams have shaped the design of the language by graciously sharing their ideas with us in lively and inspiring discussions, as well as through comments on previous versions of this document. The contributors to the Scala mailing list have also given very useful feedback that helped us improve the language and its tools. George Berger has worked tremendously to make the build process and the web presence for the book work smoothly. As a result this project has been delightfully free of technical snafus. Many people have given us feedback on early versions of the text. Thank you to Eric Armstrong, George Berger, Gilad Bracha, William Cook, Bruce Eckel, Stéphane Micheloud, Todd Millstein, David Pollak, Frank Sommers, Philip Wadler, and Matthias Zenger. We’d also like to thank Dewayne John- son and Kim Leedy for their help with the cover art. Bill would also like to thank Gary Cornell, Greg Doench, Andy Hunt, Mike Leonard, Tyler Ortman, and Dave Thomas for providing insight and Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 18

Acknowledgments xviii advice on book publishing. And we’d like to extend a very special thanks to all of our readers who contributed comments. Your comments have been very helpful to us in shaping this into an even better book. Here’s the names of everyone who submitted comments on eBook version 1 by clicking on the Suggest link, sorted first by the total number of comments submitted (higher numbers first), then alphabetically. Thanks goes to: Blair Zajac, Tony Sloane, Javier Diaz Soto, Mats Henricson, Justin Forder, David Biesack, Nigel Harrison, Donn Stephan, Mark Hayes, Calum MacLean, Les Pruszynski, Martin El- win, Dmitry Grigoriev, Ervin Varga, Marius Scurtescu, Jeff Ervin, Jamie Webb, Howard Lovatt, Shanky Surana, Alexandre Patry, Eric Willigers, Filip Moens, Peter McLain, Arkadiusz Stryjski, Boris Lorbeer, Fred Janon, Jim Menard, George Berger, Martin Smith, Richard Dallaway, Thomas Jung, An- drew Tolopko, Joshua Cough, Craig Bordelon, Juan Miguel Garcia Lopez, Matt Russell, Michel Schinz, Peter Moore, Randolph Kahle, Bjarte S. Karlsen, Colin Perkins, Hiroaki Nakamura, Martin Smith, Bhaskar Maddala, George Kollias, Kristian Nordal, Maarten Hazewinkel, Marcus Schulte, Normen Mueller, Ole Hougaard, Rafael Ferreira, Vadim Gerassimov, Cameron Tag- gart, Lars Westergren, Sam Owen, Silvestre Zabala, Will McQueen, Christo- pher Rodrigues Macias, Jeroen Dijkmeijer, Jorge Ortiz, Michel Salim, Scot McSweeney-Roberts, Tim Azzopardi, Benjamin Smith, Eelco Hillenius, F Isphording, Frederic Jean, James Iry, Jonathan Feinberg, Marcus Dubois, Paolo Losi, Robert Christie, Trustin Lee, Alx Barker, Bjorn Zetterstrom, Chee Seng Chua, Chris Hagan, Claudi Paniagua, David Bernard, Deklan Dieterly, Hans Dockter, JC Zulian, Jay Lawrence, Johannes Rudolph, John D. Heintz, John Franey, Martin Scheffler, Matthew Passell, Michael Camp- bell, Robert Alexander, Rupert Key, Simon Epstein, Thomas Boam, Tomoy- asu Kobayashi, Tyler Perkins, Aashutosh Vijayant, Amir Michail, Daniel Wellman, Dianne Marsh, Dirk Meister, Edgar Honing, Guy Oliver, Han- son Char, Jan Lohre, Jeff Heon, Johan Karlberg, John Tyler, Jon-Anders Teigen, Jonathan O’Connor, Jozef Saniga, Jörn Zaefferer, Kean Heng Lim, Kegan Gan, Marc Boehret, Maurice Walton, Narayan Iyer, Oliver Goodman, Paul Jackson, Roberto Chiaretti, Ryan Boyer, Sergey Novgorodsky, Sultan Rehman, Tom Davies, Tom Duffey, Tristan Woerth, Ulrik Rasmussen, Will Hays, William Heelan, and Wim Stolker. Now, we can’t promise this long list will make it into the printed book, but we’ll see what we can do. We wanted to let you know at least in this Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 19

Acknowledgments xix PrePrint that we find your feedback very helpful and appreciate it. Sorry if we missed anyone, as some people have submitted feedback via forums or email. It is a bit more convenient for us to process feedback submitted via the Suggest link, so we encourage that, but we appreciate your suggestions no matter how they come in. Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Trang 20

Introduction This book is a tutorial for the Scala programming language, written by peo- ple directly involved in the development of Scala. Our goal is that by reading this book, you can learn everything you need to be a productive Scala pro- grammer. Who should read this book The main target audience is programmers who want to learn to program in Scala. If you want to do your next software project in Scala, then this is the book for you. In addition, the book should be interesting to program- mers wishing to expand their horizons by learning new concepts. If you’re a Java programmer, for example, reading this book will expose you to many concepts from functional programming as well as advanced object oriented ideas. We believe learning Scala can help you become a better programmer in general. General programming knowledge is assumed. While Scala is a fine first programming language, this is not the book to use to learn programming. On the other hand, no specific knowledge of programming languages is required. Even though most people use Scala on the Java platform, this book does not presume you know anything about Java. However, we expect many readers to be familiar with Java, and so we sometimes compare Scala to Java to help such readers understand the differences. How to use this book The main purpose of this book is to serve as a tutorial to help you learn to program in Scala. Thus, the recommended way to read this book is in chapter Prepared for jacques weiss Cover · Overview · Contents · Discuss · Suggest · Glossary · Index

Hiển thị 20 trang đầu. Tải tài liệu để xem đầy đủ.

Bình luận (0)

Đăng nhập để tham gia bình luận

Chưa có bình luận nào. Hãy là người đầu tiên!