ebook img

F# for Fun and Profit eBook PDF

1930 Pages·2013·13.843 MB·English
by  Scott W
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 F# for Fun and Profit eBook

Table of Contents Getting started Introduction 1.1 Contents of the book 1.2 "Why use F#?" in one page 1.3 Installing and using F# 1.4 F# syntax in 60 seconds 1.5 Learning F# 1.6 Troubleshooting F# 1.7 Low-risk ways to use F# at work 1.8 Twenty six low-risk ways to use F# at work 1.8.1 Using F# for development and devops scripts 1.8.2 Using F# for testing 1.8.3 Using F# for database related tasks 1.8.4 Other interesting ways of using F# at work 1.8.5 Why use F#? The "Why use F#?" Series 2.1 Introduction to the 'Why use F#' series 2.1.1 F# syntax in 60 seconds 2.1.2 Comparing F# with C#: A simple sum 2.1.3 Comparing F# with C#: Sorting 2.1.4 Comparing F# with C#: Downloading a web page 2.1.5 Four Key Concepts 2.1.6 Conciseness 2.1.7 Type inference 2.1.8 Low overhead type definitions 2.1.9 Using functions to extract boilerplate code 2.1.10 Using functions as building blocks 2.1.11 1 Pattern matching for conciseness 2.1.12 Convenience 2.1.13 Out-of-the-box behavior for types 2.1.14 Functions as interfaces 2.1.15 Partial Application 2.1.16 Active patterns 2.1.17 Correctness 2.1.18 Immutability 2.1.19 Exhaustive pattern matching 2.1.20 Using the type system to ensure correct code 2.1.21 Worked example: Designing for correctness 2.1.22 Concurrency 2.1.23 Asynchronous programming 2.1.24 Messages and Agents 2.1.25 Functional Reactive Programming 2.1.26 Completeness 2.1.27 Seamless interoperation with .NET libraries 2.1.28 Anything C# can do... 2.1.29 Why use F#: Conclusion 2.1.30 Thinking Functionally The "Thinking Functionally" Series 3.1 Thinking Functionally: Introduction 3.1.1 Mathematical functions 3.1.2 Function Values and Simple Values 3.1.3 How types work with functions 3.1.4 Currying 3.1.5 Partial application 3.1.6 Function associativity and composition 3.1.7 Defining functions 3.1.8 Function signatures 3.1.9 Organizing functions 3.1.10 Attaching functions to types 3.1.11 2 Worked example: A stack based calculator 3.1.12 Understanding F# The "Expressions and syntax" Series 4.1 Expressions and syntax: Introduction 4.1.1 Expressions vs. statements 4.1.2 Overview of F# expressions 4.1.3 Binding with let, use, and do 4.1.4 F# syntax: indentation and verbosity 4.1.5 Parameter and value naming conventions 4.1.6 Control flow expressions 4.1.7 Exceptions 4.1.8 Match expressions 4.1.9 Formatted text using printf 4.1.10 Worked example: Parsing command line arguments 4.1.11 Worked example: Roman numerals 4.1.12 The "Understanding F# types" Series 4.2 Understanding F# types: Introduction 4.2.1 Overview of types in F# 4.2.2 Type abbreviations 4.2.3 Tuples 4.2.4 Records 4.2.5 Discriminated Unions 4.2.6 The Option type 4.2.7 Enum types 4.2.8 Built-in .NET types 4.2.9 Units of measure 4.2.10 Understanding type inference 4.2.11 Choosing between collection functions 4.3 The "Object-oriented programming in F#" Series 4.4 Object-oriented programming in F#: Introduction 4.4.1 Classes 4.4.2 Inheritance and abstract classes 4.4.3 3 Interfaces 4.4.4 Object expressions 4.4.5 The "Computation Expressions" Series 4.5 Computation expressions: Introduction 4.5.1 Understanding continuations 4.5.2 Introducing 'bind' 4.5.3 Computation expressions and wrapper types 4.5.4 More on wrapper types 4.5.5 Implementing a builder: Zero and Yield 4.5.6 Implementing a builder: Combine 4.5.7 Implementing a builder: Delay and Run 4.5.8 Implementing a builder: Overloading 4.5.9 Implementing a builder: Adding laziness 4.5.10 Implementing a builder: The rest of the standard methods 4.5.11 Organizing modules in a project 4.6 The "Dependency cycles" Series 4.7 Cyclic dependencies are evil 4.7.1 Refactoring to remove cyclic dependencies 4.7.2 Cycles and modularity in the wild 4.7.3 The "Porting from C#" Series 4.8 Porting from C# to F#: Introduction 4.8.1 Getting started with direct porting 4.8.2 Functional Design The "Designing with types" Series 5.1 Designing with types: Introduction 5.1.1 Single case union types 5.1.2 Making illegal states unrepresentable 5.1.3 Discovering new concepts 5.1.4 Making state explicit 5.1.5 Constrained strings 5.1.6 Non-string types 5.1.7 Designing with types: Conclusion 5.1.8 4 Algebraic type sizes and domain modelling 5.2 Thirteen ways of looking at a turtle 5.3 Thirteen ways of looking at a turtle (part 2) 5.3.1 Thirteen ways of looking at a turtle - addendum 5.3.2 Functional Patterns How to design and code a complete program 6.1 A functional approach to error handling (Railway oriented programming) 6.2 Railway oriented programming: Carbonated edition 6.2.1 The "Understanding monoids" Series 6.3 Monoids without tears 6.3.1 Monoids in practice 6.3.2 Working with non-monoids 6.3.3 The "Understanding Parser Combinators" Series 6.4 Understanding Parser Combinators 6.4.1 Building a useful set of parser combinators 6.4.2 Improving the parser library 6.4.3 Writing a JSON parser from scratch 6.4.4 The "Handling State" Series 6.5 Dr Frankenfunctor and the Monadster 6.5.1 Completing the body of the Monadster 6.5.2 Refactoring the Monadster 6.5.3 The "Map and Bind and Apply, Oh my!" Series 6.6 Understanding map and apply 6.6.1 Understanding bind 6.6.2 Using the core functions in practice 6.6.3 Understanding traverse and sequence 6.6.4 Using map, apply, bind and sequence in practice 6.6.5 Reinventing the Reader monad 6.6.6 Map and Bind and Apply, a summary 6.6.7 The "Recursive types and folds" Series 6.7 Introduction to recursive types 6.7.1 Catamorphism examples 6.7.2 5 Introducing Folds 6.7.3 Understanding Folds 6.7.4 Generic recursive types 6.7.5 Trees in the real world 6.7.6 The "A functional approach to authorization" Series 6.8 A functional approach to authorization 6.8.1 Constraining capabilities based on identity and role 6.8.2 Using types as access tokens 6.8.3 Testing An introduction to property-based testing 7.1 Choosing properties for property-based testing 7.2 Examples and Walkthroughs Worked example: Designing for correctness 8.1 Worked example: A stack based calculator 8.2 Worked example: Parsing command line arguments 8.3 Worked example: Roman numerals 8.4 Commentary on 'Roman Numerals Kata with Commentary' 8.5 Calculator Walkthrough: Part 1 8.6 Calculator Walkthrough: Part 2 8.6.1 Calculator Walkthrough: Part 3 8.6.2 Calculator Walkthrough: Part 4 8.6.3 Enterprise Tic-Tac-Toe 8.7 Enterprise Tic-Tac-Toe, part 2 8.7.1 Writing a JSON parser from scratch 8.8 Other Ten reasons not to use a statically typed functional programming language 9.1 Why I won't be writing a monad tutorial 9.2 Is your programming language unreasonable? 9.3 6 We don't need no stinking UML diagrams 9.4 Introvert and extrovert programming languages 9.5 Swapping type-safety for high performance using compiler directives 9.6 7 Introduction F# for Fun and Profit eBook This is an eBook version of my site fsharpforfunandprofit.com, created by popular request for people who want to read it offline on their kindle or phone. Special thanks to Roman Provaznik for the final nag. The site (and this book) aims to introduce you to F# and show you ways that F# can help in day-to-day development of mainstream commercial business software. On the way, I hope to open your mind to the joys of functional programming - it really is fun! Many of the posts were not really designed to be in a book, but I have arranged them so that beginner posts come first, and more advanced posts later. About F# If you are completely new to F#, F# is a general purpose functional/hybrid programming language which is great for tackling almost any kind of software challenge. F# is free and open source, and runs on Linux, Mac, Windows and more. To download and install F#, or to find out more, go to F# Foundation site at fsharp.org. Getting started Next, before randomly dipping into the posts, you should read the "why use F#?" page and then the whole "why use F#" series. After that the "site contents" page provides suggestions for further reading on functions, types and more. There is a page with some advice on learning F#, and if you have problems trying to get your code to compile, the troubleshooting F# page might be helpful. I will assume that you do not need instruction in the basics of programming and that you are familiar with C#, Java, or a similar C-like language. It will also be helpful if you are familiar with the Mono/.NET library. On the other hand, I will not assume that you have a mathematical or computer science background. There will be no mathematical notation, and no mysterious concepts like "functor", "category theory" and "anamorphism". If you are already familiar with Haskell or ML, this is probably not the place for you! 8 Introduction Also, I will not attempt to cover highly technical or mathematical applications. F# is an excellent tool for these domains, but it requires an approach that is different from business software. 9 Contents of the book Getting started Installing and using F# will get you started. Why use F#? An interactive tour of F#. Learning F# has tips to help you learn more effectively. Troubleshooting F# for when you have problems getting your code to compile. and then you can try... Twenty six low-risk ways to use F# at work. You can start right now -- no permission needed! Tutorials The following series are tutorials on the key concepts of F#. Thinking functionally starts from basics and explains how and why functions work the way they do. Expressions and syntax covers the common expressions such as pattern matching, and has a post on indentation. Understanding F# types explains how to define and use the various types, including tuples, records, unions, and options. Designing with types explains how to use types as part of the design process, making illegal states unrepresentable. Choosing between collection functions. If you are coming to F# from C#, the large number of list functions can be overwhelming, so I have written this post to help guide you to the one you want. Property-based testing: the lazy programmer's guide to writing 1000's of tests. Understanding computation expressions demystifies them and shows how you can create your own. Functional patterns These posts explain some core patterns in functional programming -- concepts such as "map", "bind", monads and more. Railway Oriented Programming: A functional approach to error handling State Monad: An introduction to handling state using the tale of Dr Frankenfunctor and the Monadster. 10

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.