ebook img

Steps in Scala PDF

506 Pages·2010·12.248 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Steps in Scala

This page intentionally left blank STEPS IN SCALA AnIntroductiontoObject-FunctionalProgramming Object-functionalprogrammingisalreadyhere.Scalaisthemostprominentrep- resentativeofthisexcitingapproachtoprogramming,bothinthesmallandinthe large. In this book we show how Scala proves to be a highly expressive, concise, and scalable language, which grows with the needs of the programmer, whether professionalorhobbyist. Readthebooktoseehowto: • leveragethefullpoweroftheindustry-provenJVMtechnologywithalanguagethatcould havecomefromthefuture; • learn Scala step-by-step, following our complete introduction and then dive into spe- ciallychosendesignchallengesandimplementationproblems,inspiredbythereal-world, softwareengineeringbattlefield; • embracethepowerofstatictypingandautomatictypeinference; • usethedualobjectandfunctionalorientednaturescombinedatScala’score,toseehow towritecodethatisless“boilerplate”andtowitnessarealincreaseinproductivity. Use Scala for fun, for professional projects, for research ideas. We guarantee the experiencewillberewarding. Christos K. K. Loverdos is a research inclined computer software profes- sional.HeholdsaB.Sc.andanM.Sc.inComputerScience.Hehasbeenworking inthesoftwareindustryformorethantenyears,designingandimplementingflex- ible,enterprise-levelsystemsandmakingstrategictechnicaldecisions.Hehasalso publishedresearchpapersontopicsincludingdigitaltypography,service-oriented architectures,and highly available distributed systems. Last but not least,he is an advocateofopensourcesoftware. Apostolos Syropoulos is a computer scientist. He holds a B.Sc. in Physics, anM.Sc.inComputerScience,andaPh.D.inTheoreticalComputerScience.His researchinterestsfocusoncomputabilitytheory,categorytheory,fuzzysettheory, and digital typography. He has authored or co-authored six books,was co-editor ofamulti-authorvolume,andhaspublishedmorethan50papersandarticles. STEPS IN SCALA An Introduction to Object-Functional Programming CHRISTOS K. K. LOVERDOS APOSTOLOS SYROPOULOS CAMBRIDGE UNIVERSITY PRESS Cambridge, New York, Melbourne, Madrid, Cape Town, Singapore, São Paulo, Delhi, Dubai, Tokyo Cambridge University Press The Edinburgh Building, Cambridge CB2 8RU, UK Published in the United States of America by Cambridge University Press, New York www.cambridge.org Information on this title: www.cambridge.org/9780521762175 © C. K. K. Loverdos and A. Syropoulos 2010 This publication is in copyright. Subject to statutory exception and to the provision of relevant collective licensing agreements, no reproduction of any part may take place without the written permission of Cambridge University Press. First published in print format 2010 ISBN-13 978-0-511-90054-9 eBook (EBL) ISBN-13 978-0-521-76217-5 Hardback ISBN-13 978-0-521-74758-5 Paperback Cambridge University Press has no responsibility for the persistence or accuracy of urls for external or third-party internet websites referred to in this publication, and does not guarantee that any content on such websites is, or will remain, accurate or appropriate. ToKaterina,whoisalwayshereandisconstantlymakingmeabetterperson CKKL (cid:1)τoυς γovε´ις µoυ (cid:3)εω´ργιo και Bασιλικη´ και στov γιo µoυ (cid:5)ηµη´τριo-(cid:3)εω´ ργιo AS Contents Preface page xiii 1 Introduction 1 1.1 Objectorientation 1 1.2 Anoverviewoffunctionalprogramming 7 1.3 Extendablelanguages 9 1.4 Scala:beyondtheJavaprogramminglanguage 14 2 Corefeatures 16 2.1 “HelloWorld!”inScala 16 2.2 Scala’sbasictypes 18 2.3 Classesandobjects 24 2.4 Somebasicoperators 29 2.5 Basicbuilt-incontrolstructures 32 2.6 Subclassesandinheritance 38 2.7 Functions 42 2.8 Arraysandtuples 48 2.9 Commandlinearguments 53 2.10 Sets 56 2.11 Hashtables 59 2.12 Memofunctions 62 2.13 Lists 64 2.14 Strings 74 2.15 Regularexpressions 76 2.16 ScientificcomputationwithScala 84 2.17 Innerclasses 87 2.18 Packages 88 2.19 Documentationcomments 90 2.20 Annotations 92 vii viii Contents 3 Advancedfeatures 95 3.1 Playingwithtrees 95 3.2 Moreaboutpatternmatching 103 3.2.1 Typesofpatterns 103 3.2.2 Sealedclasses 107 3.2.3 Optionalvalues 108 3.3 Traitsandmix-incomposition 109 3.4 Sortingobjects 116 3.5 Moreonfunctions 118 3.6 Polymorphism 125 3.6.1 Typesofpolymorphism 125 3.6.2 Overloading 127 3.6.3 Implicitconversion:aformofcoercion 128 3.6.4 Parametricpolymorphism 131 3.6.5 Moreonimplicitparameters 136 3.6.6 Inclusionpolymorphism 137 3.6.7 Covariance,contravarianceandinvariance 138 3.6.8 Boundedpolymorphism 140 3.6.9 Viewsandviewbounds 143 3.6.10 Existentialtypes 144 3.6.11 Typeprojections 147 3.6.12 Typeerasure 147 3.7 Nominalandstructuraltyping 148 ∗ 3.8 Higherorderpolymorphism 150 3.9 Streamsare“infinite”lists! 156 ∗ 3.10 Moreonmemofunctions 158 3.11 Assertions 159 3.12 Settersandgetters 161 ∗ 3.13 Monads 163 4 Parserbuilders 171 4.1 Languageparsers 171 4.2 Scala’sparserbuilders 174 4.3 Aninterpreterforatoylanguage 177 4.4 Domain-specificlanguages 184 4.5 Monadicparsing 185 5 XMLprocessing 187 5.1 WhatisXML? 187 5.2 BasicXMLcontentmanipulation 189 5.3 ProducingXHTMLcontentwithScala 193 5.4 XMLinputandoutput 196

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.