Summary Get Programming with F#: A guide for .NET Developers shows you how to upgrade your .NET development skills by adding a touch of functional programming in F#. In just 43 bite-sized chunks, you'll learn how to use F# to tackle the most common .NET programming tasks.Examples use the familiar Visual Studio environment, so you'll be instantly comfortable. Packed with enlightening examples, real-world use cases, and plenty of easy-to-digest code, this easy-to-follow tutorial will make you wonder why you didn't pick up F# years ago! FForewords by Dustin Campbell of Microsoft and Tomas Petricek of fsharpWorks. Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the Technology Your .NET applications need to be good for the long haul. F#'s unique blend of functional and imperative programming is perfect for writing code that performs flawlessly now and keeps running as your needs grow and change. It takes a little practice to master F#'s functional-first style, so you may as well get programming! About the Book Get Programming with F#: A guide for .NET developers teaches F# through 43 example-based lessons with built-in exercises so you can learn the only way that really works: by practicing. The book upgrades your .NET skills with a touch of functional programming in F#. You'll pick up core FP principles and learn techniques for iron-clad reliability and crystal clarity. You'll discover productivity techniques for coding F# in Visual Studio, functional design, and integrating functional and OO code. What's Inside Learn how to write bug-free programs Turn tedious common tasks into quick and easy ones Use minimal code to work with JSON, CSV, XML, and HTML data Integrate F# with your existing C# and VB.NET applications Create web-enabled applications About the Reader Written for intermediate C# and Visual Basic .NET developers. No experience with F# is assumed. About the Author Isaac Abraham is an experienced .NET developer and trainer. He's an F# MVP for his contributions to the .NET community. Contents 3 Foreword 5 Preface 8 About this Book 10 Welcome 14 What is F#, and why does it matter? 15 F# and .NET 25 Summary 27 1 F# & Visual Studio 28 VS Experience 29 Installing VS2015 with F# 30 Configuring Visual Studio for F# 31 Getting the best out of VS 2015 and F# 32 Summary 35 First F# Program 36 F# project types 36 Debugging applications in F# 41 Writing your first F# program 42 Summary 44 REPL 45 Code-focused developer processes 45 Enter the REPL 48 F# scripts in Visual Studio 52 Summary 55 2 Hello F# 56 Saying a little, doing a lot 57 Binding values in F# 59 Scoping values 61 Summary 67 Trusting the Compiler 68 Type inference as we know it 68 F# type-inference basics 72 Following the breadcrumbs 76 Summary 79 Immutable Data 80 Working with mutable data—a recap 80 Being explicit about mutation 82 Modeling state 85 Summary 90 Expressions & Statements 91 Comparing statements and expressions 91 Using expressions in F# 95 Forcing statement-based evaluation 100 Summary 101 Capstone 1 102 Defining the problem 102 Some advice before you start 103 Starting small 103 Implementing core logic 105 Testing in scripts 107 Moving to a full application 108 Summary 108 3 Types & Functions 109 Tuples 111 The need for tuples 111 Tuple basics 113 More-complex tuples 116 Tuple best practices 118 Summary 120 Records 121 POCOs done right: records in F# 124 Doing more with records 127 Tips and tricks with records 131 Summary 133 Composable Functions 135 Partial function application 136 Constraining functions 138 Composing functions together 145 Summary 146 Code without Classes 148 Using namespaces and modules 149 Moving from scripts to applications 153 Tips for working with modules and namespaces 157 Summary 158 Code Reuse 159 Reuse in the world of LINQ 161 Implementing higher-order functions in F# 164 Dependencies as functions 166 Summary 169 Capstone 2 170 Defining the problem 170 Some advice before you start... 171 Getting started 172 Creating a domain 172 Creating behaviors 172 Abstraction and reuse through higher-order functions 173 Writing a console application 177 Referencing files from scripts 179 Summary 180 4 Collections 181 Collections 182 F# collection basics 183 Collection types in F# 191 Summary 194 Collection Functions 195 Mapping functions 196 Grouping functions 201 More on collections 203 Summary 205 Maps, Dictionaries & Sets 206 Dictionaries 206 The F# Map 209 Sets 212 Summary 213 Way to Success 215 Understanding aggregations and accumulators 215 Saying hello to fold 218 Composing functions with fold 223 Summary 226 Capstone 3 228 Defining the problem 228 Removing mutability 229 Writing transactions to disk 234 Rehydrating an account from disk 235 Summary 236 5 F# Type System 237 Program Flow 238 A tour around loops in F# 238 Branching logic in F# 241 Flexible pattern matching 246 To match or not to match 249 Summary 250 Modeling Relationships 251 Composition in F# 251 Discriminated unions in F# 253 Tips for working with discriminated unions 258 More about discriminated unions 261 Summary 262 Fixing the Billion-Dollar Mistake 264 Working with missing values 264 Improving matters with the F# type system 268 Using the Option module 271 Collections and options 275 Summary 276 Business Rules as Code 277 Specific types in F# 278 Encoding business rules with marker types 284 Results vs. exceptions 288 Summary 289 Capstone 4 291 Defining the problem 291 Stronger typing with discriminated unions 292 Applying Option types with the outside world 296 Implementing business rules with types 299 Summary 303 6 Living on NET Platform 304 Consuming C# from F# 305 Referencing C# code in F# 305 The Visual Studio experience 308 Working with OO constructs 312 Summary 315 NUget Packages 316 Using NuGet with F# 316 Working with Paket 322 Summary 326 Exposing F# Types & Functions to C# 327 Using F# types in C# 328 More on F# interoperability 332 Summarizing F# to C# interoperability 334 Summary 336 Hybrid Langiuage Applications 337 Crossing language boundaries 337 Case study—WPF monopoly 342 Summary 347 Capstone 5 348 Defining the problem 348 Plugging in a third-party NuGet package 350 Connecting F# code to a WPF front end 351 Common fields on discriminated unions 355 Polishing up F# APIs for consumers 356 Working with pure functions in a mutable world 357 Summary 358 7 Data 359 Type Providers 360 Understanding type providers 360 Working with your first type provider 362 Summary 369 Schemas from live Data 370 Working with JSON 370 Avoiding problems with live schemas 374 Mixing local and remote datasets 376 Summary 380 SQL 381 Creating a basic database 382 Introducing the SqlClient project 383 Using the SQLProvider 388 Summary 392 Type Provider backed APIs 393 Creating a tightly coupled type provider API 394 Creating a decoupled API 398 Summary 404 Type Providers in real World 406 Securely accessing connection strings with type providers 406 Manually passing connection strings 410 Continuous integration with type providers 412 Summary 415 Capstone 6 416 Defining the problem 416 Hooking up a SQL database 417 Creating a SQL data access layer 418 Making a pluggable data access layer 424 Summary 427 8 Web Programming 428 Asynchronous Workflows 429 Comparing synchronous and asynchronous models 429 Introducing asynchronous workflows 433 Composing asynchronous values 436 Using fork/join 437 Using tasks and async workflows 439 Summary 442 Exposing Data over HTTP 443 Getting up and running with the ASP .NET Web API 443 Abstracting the Web API from F# 448 Working with Async 452 Introducing Suave 453 Summary 456 Consuming HTTP Data 457 Using FSharp.Data to work with HTTP endpoints 458 Working with HTTP.fs 461 Using the Swagger type provider 464 Summary 467 Capstone 7 468 Defining the problem 468 Adding Web API support to your application 469 Consuming data with Swagger 471 Enriching the API 474 Summary 477 9 Unit Testing 478 Unit Testing in F# 479 Knowing when to unit test in F# 479 Performing basic unit testing in F# 482 Testing DSLs in F# 486 Summary 490 Property-based Testing in F# 491 Understanding property-based testing 492 Introducing FsCheck 495 Controlling data generation 498 Summary 502 Web Testing 503 Web automation with Canopy 504 Web tests with Canopy 508 Summary 512 Capstone 8 513 Defining the problem 513 Writing API tests 514 Testing the Web API tier 517 Using property-based tests 518 Summary 520 10 Where next 521 F# Community 523 A.1 The F# community 523 A.2 Coding in the open source world 526 A.3 A real-world example of open source contributions 526 Summary 528 F# in my Organization 529 B.1 Introducing F# to others 530 B.2 Introducing F# to your code base 534 Summary 538 F# Resources 539 C.1 Websites 539 C.2 Social networks 541 C.3 Projects and language 542 Summary 544 F# Libraries 545 D.1 Libraries 545 D.2 The F# toolchain 556 Summary 557 Other F# Features 558 E.1 Object-oriented support 558 E.2 Exception handling 560 E.3 Resource management 561 E.4 Casting 561 E.5 Active patterns 563 E.6 Computation expressions 563 E.7 Code quotations 564 E.8 Units of measure 564 E.9 Lazy computations 565 E.10 Recursion 565 Index 566 Basic F# Syntax, Types & Functions 579 Discriminated Unions, Pattern Matching & Lists 580 Summary Get Programming with F#: A guide for.NET developers teaches F# through 43 example-based lessons with built-in exercises so you can learn the only way that really works: by practicing. The book upgrades your.NET skills with a touch of functional programming in F#. You'll pick up core FP principles and learn techniques for iron-clad reliability and crystal clarity. You'll discover productivity techniques for coding F# in Visual Studio, functional design, and integrating functional and OO code. Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the Technology Your.NET applications need to be good for the long haul. F#'s unique blend of functional and imperative programming is perfect for writing code that performs flawlessly now and keeps running as your needs grow and change. It takes a little practice to master F#'s functional-first style, so you may as well get programming! What's Inside Learn how to write bug-free programs Turn tedious common tasks into quick and easy ones Use minimal code to work with JSON, CSV, XML, and HTML data Integrate F# with your existing C# and VB.NET applications Create web-enabled applications About the Reader Written for intermediate C# and Visual Basic.NET developers. No experience with F# is assumed. Table of Contents Unit 1 - F# AND VISUAL STUDIO Lesson 1 - The Visual Studio experience Lesson 2 - Creating your first F# program Lesson 3 - The REPL-changing how we develop Unit 2 - HELLO F# Lesson 4 - Saying a little, doing a lot Lesson 5 - Trusting the compiler Lesson 6 - Working with immutable data Lesson 7 - Expressions and statements Lesson 8 Capstone 1 Unit 3 - TYPES AND FUNCTIONS Lesson 9 - Shaping data with tuples Lesson 10 - Shaping data with records Lesson 11 - Building composable functions Lesson 12 - Organizing code without classes Lesson 13 - Achieving code reuse in F# Lesson 14 - Capstone 2 Unit 4 - COLLECTIONS IN F# Lesson 15 - Working with collections in F# Lesson 16 - Useful collection functions Lesson 17 - Maps, dictionaries, and sets Lesson 18 - Folding your way to success Lesson 19 - Capstone 3 Unit 5 - THE PIT OF SUCCESS WITH THE F# TYPE SYSTEM Lesson 20 - Program flow in F# Lesson 21 - Modeling relationships in F# Lesson 22 - Fixing the billion-dollar mistake Lesson 23 - Business rules as code Lesson 24 - Capstone 4 Unit 6 - LIVING ON THE.NET PLATFORM Lesson 25 - Consuming C# from F# Lesson 26 - Working with NuGet packages Lesson 27 - Exposing F# types and functionsto C# Lesson 28 - Architecting hybrid language applications Lesson 29 - Capstone 5 Unit 7 - WORKING WITH DATA Lesson 30 - Introducing type providers Lesson 31 - Building schemas from live data Lesson 32 - Working with SQL Lesson 33 - Creating type provider-backed APIs Lesson 34 - Using type providers in the real world Lesson 35 - Capstone 6 Unit 8 - WEB PROGRAMMING Lesson 36 - Asynchronous workflows Lesson 37 - Exposing data over HTTP Lesson 38 - Consuming HTTP data Lesson 39 - Capstone 7 Unit 9 - UNIT TESTING Lesson 40 - Unit testing in F# Lesson 41 - Property-based testing in F# Lesson 42 - Web testing Lesson 43 - Capstone 8 Unit 10 - WHERE NEXT? Appendix A - The F# community Appendix B - F# in my organization Appendix C - Must-visit F# resources Appendix D - Must-have F# libraries Appendix E - Other F# language feature Annotation F♯ leads to quicker development time and a lower total cost of ownership. Its powerful feature set allows developers to more succinctly express their intent, and encourages best practices - leading to higher quality deliverables in less time. This guide how to upgrade your .NET development skills by adding a touch of functional programming in F♯. In just 43 bite-size chunks, you'll learn to use F♯ to tackle the most common .NET programming tasks. You'll start with the basics of F♯ and functional programming, building on your existing skills in the .NET framework. Examples use the familiar Visual Studio environment, so you'll be instantly comfortable
Get Programming with F#: A guide for.NET Developers shows you how to upgrade your.NET development skills by adding a touch of functional programming in F#. In just 43 bite-sized chunks, you'll learn how to use F# to tackle the most common.NET programming tasks.Examples use the familiar Visual Studio environment, so you'll be instantly comfortable. Packed with enlightening examples, real-world use cases, and plenty of easy-to-digest code, this easy-to-follow tutorial will make you wonder why you didn't pick up F# years ago!
Get Programming with F#: A guide for .NET Developers shows you how to upgrade your .NET development skills by adding a touch of functional programming in F#. In just 43 bite-sized chunks, you'll learn how to use F# to tackle the most common .NET programming tasks. Examples use the familiar Visual Studio environment, so you'll be instantly comfortable. Packed with enlightening examples, real-world use cases, and plenty of easy-to-digest code, this easy-to-follow tutorial will make you wonder why you didn't pick up F# years ago!