Wiley
Wiley.com
Print this page Share

Professional F# 2.0

ISBN: 978-0-470-52801-3
432 pages
November 2010
Professional F# 2.0 (047052801X) cover image
This is a book on the F# programming language.

On the surface of things, that is an intuitively obvious statement, given the title of this book. However, despite the apparent redundancy in saying it aloud, the sentence above elegantly describes what this book is about: The authors are not attempting to teach developers how to accomplish tasks from other languages in this one, nor are they attempting to evangelize the language or its feature set or its use "over" other languages. They assume that you are considering this book because you have an interest in learning the F# language: its syntax, its semantics, its pros and cons, and its use in concert with other parts of the .NET ecosystem.

The intended reader is a .NET developer, familiar with at least one of the programming languages in the .NET ecosystem. That language might be C# or Visual Basic, or perhaps C++/CLI, IronPython or IronRuby.

See More

FOREWORD xxi

INTRODUCTION xxiii

PART 0: BEGINNINGS

CHAPTER 1: PRIMER 3

Setup 5

It’s that Time of Year Again… 7

Strategy 10

The Delegate Strategy 12

Lambda Calculus (Briefly) 17

Type Inference 22

Immutability 26

Expressions, not Statements 27

Summary 28

PART I: BASICS

CHAPTER 2: LEXICAL STRUCTURE 31

Comments 31

Identifiers 32

Preprocessor Directives 33

Significant Whitespace 34

Summary 35

CHAPTER 3: PRIMITIVE TYPES 37

Boolean 37

Numeric Types 38

Bitwise Operations 40

Floating-Point Types 40

Arithmetic Conversions 41

String and Character Types 42

Unit 43

Units of Measure Types 43

Literal Values 44

Summary 45

CHAPTER 4: CONTROL FLOW 47

Basic Decisions: if 47

Looping: while/do 49

Looping: for 50

Exceptions 50

Summary 53

CHAPTER 5: COMPOSITE TYPES 55

Option Types 55

Tuples 58

Arrays 60

Lists 65

Using Lists and Arrays 72

Sequences 74

Maps 79

Sets 82

Summary 83

CHAPTER 6: PATTERN MATCHING 85

Basics 85

Pattern Types 88

Pattern Guards 94

Active Patterns 95

Summary 102

PART II: OBJECTS

CHAPTER 7: COMPLEX COMPOSITE TYPES 105

Type Abbreviations 105

Enum Types 106

Discriminated Union Types 109

Structs 114

Record Types 119

Summary 123

CHAPTER 8: CLASSES 125

Basics 125

Members 132

Static Members 146

Delegates and Events 149

Access Modifiers 155

Type Extensions 157

Summary 159

CHAPTER 9: INHERITANCE 161

Basics 161

Overriding 166

Casting 171

Interfaces 177

Object Expressions 181

Summary 181

CHAPTER 10: GENERICS 183

Basics 183

Type Constraints 186

Statically Resolved Type Parameters 189

Summary 190

CHAPTER 11: PACKAGING 191

Namespaces 191

Modules 193

Summary 195

CHAPTER 12: CUSTOM ATTRIBUTES 197

Using Custom Attributes 197

Creation and Consumption 203

CHAPTER 13: FUNCTIONS 209

Traditional Function Calls 209

Mathematical Functions 210

Coming from C# 211

Function Arguments and Return Values 211

Partial Application 215

Functions as First Class 218

Summary 223

CHAPTER 14: IMMUTABLE DATA 225

The Problem with State 225

State Safety 226

Data Mutation 232

Performance Considerations 239

Summary 245

CHAPTER 15: DATA TYPES 247

Ambiguously Typed Data 247

Failing Fast 248

Specificity 248

Summary 255

CHAPTER 16: LIST PROCESSING 257

Collection Abstractions 257

Module Functions 258

Collection Subsets 258

Element Transformations 260

Accumulators 263

Summary 267

CHAPTER 17: PIPELINING AND COMPOSITION 269

Basic Composition and Pipelining 269

Applying Pipelining and Composition 275

Summary 280

PART IV: APPLICATIONS

CHAPTER 18: C# 283

Overview 283

Calling C# Libraries from F# 284

Calling F# Libraries from C# 289

Rules of Thumb for Writing F# APIs 294

Summary 295

CHAPTER 19: DATABASES 297

Overview 297

Retrieving Data Using ADO.NET 298

F# and Object Relational Mapping 302

Introducing F# Active Record (FAR) 303

How FAR Works 306

Summary 315

CHAPTER 20: XML 317

Overview 317

F# and LINQ-to-XML 318

F# and XML DOM 325

F#, XML, and Active Patterns 329

Summary 339

CHAPTER 21: ASP.NET MVC 341

Overview 341

FORECAST’R — The World’s Simplest Weather

Forecast Site 342

Summary 355

CHAPTER 22: SILVERLIGHT 357

Overview 357

Visual Studio Project Templates 360

The Silverlight Toolkit 365

Data Binding 368

Calculating Moving Average 372

Putting It All Together 373

Summary 376

CHAPTER 23: SERVICES 377

Overview 377

An F#-Based Weather Service 378

Leveraging the Domain Model 380

Writing the Service Controller 381

Consuming Services 385

Summary 390

INDEX 391

See More

Ted Neward is an independent consultant, an authority in Java and .NET technologies, a Microsoft MVP, and in the INETA Speaker's Bureau.

Aaron C. Erickson is a software developer, technology writer, and frequent guest speaker.

Talbott Crowell is a solution architect with 30 years of experience developing software and co-leads the New England F# User Group.

Richard Minerich is a blogger, speaker, and Microsoft MVP and co-leads the New England F# User Group.

See More
Download TitleSizeDownload
Readme 458 bytes Click to Download
Code Download :: All Chapters
The originally posted code files were missing the Generics.fs file in the Objects folder. The code files were updated to include this file during the last week of January 2011.
645.06 KB Click to Download
See More

Do you think you've discovered an error in this book? Please check the list of errata below to see if we've already addressed the error. If not, please submit the error via our Errata Form. We will attempt to verify your error; if you're right, we will post a correction below.

ChapterPageDetailsDatePrint Run
Note about Code Download
The originally posted code files were missing the Generics.fs file in the Objects folder. The code files were updated to include this file during the last week of January 2011.
1/26/11
16 Error in Code
"count / sum(ages)"; 

should be:
 "sum(ages) / count"
7/23/11
17 Name Error
Loronzo Church

should be:
Alonzo Church
7/22/11
76 Error in Text
bottom of page, Seq "Meta" Functions:
says that these functions "manipulate lists."

should read:
"manipulate sequences."
8/17/11
See More

Related Titles

Back to Top