Book Image

Mastering F#

By : Alfonso García-Caro Núñez, Suhaib Fahad
Book Image

Mastering F#

By: Alfonso García-Caro Núñez, Suhaib Fahad

Overview of this book

F# is a multi-paradigm programming language that encompasses object-oriented, imperative, and functional programming language properties. Now adopted in a wide range of application areas and is supported both by industry-leading companies who provide professional tools and by an active open community, F# is rapidly gaining popularity as it emerges in digital music advertising, creating music-focused ads for Spotify, Pandora, Shazam, and anywhere on the web. This book will guide you through the basics and will then help you master F#. The book starts by explaining how to use F# with Visual Studio, file ordering, and the differences between F# and C# in terms of usage. It moves on to explain the functional core of F# such as data types, type declarations, immutability, strong type interference, pattern matching, records, F# data structures, sequence expressions, and lazy evaluation. Next, the book takes you through imperative and asynchronous programming, F# type providers, applications, and testing in F#. Finally, we look into using F# with distributed programming and using F# as a suitable language for data science. In short, this book will help you learn F# for real-world applications and increase your productivity with functional programming.
Table of Contents (16 chapters)

Preface

F# is a multiparadigm programming language that encompasses object-oriented, imperative, and functional programming language properties. Now adopted in a wide range of application areas and supported both by industry-leading companies who provide professional tools and by an active open community, F# is rapidly gaining popularity as it emerges in digital music advertising and creating music focused ads for Spotify, Pandora, Shazam, and anywhere on the web.

What this book covers

Chapter 1, Getting Started with F#, explains how to get started with F# with Visual Studio. A Simple hello world program is created and details about the project structure and file ordering and the differences between F# and C# in terms of usage are discussed.

Chapter 2, Functional Core with F#, teaches you about the functional core of F#, such as data types, type declarations, immutability, strong type interference, pattern matching, records, F# data structures, sequence expressions, lazy evaluation, making side effects explicit, and so on.

Chapter 3, Data Structures in F#, helps you understand how to use the available data structures in F# and write some basic custom data structures.

Chapter 4, Imperative Programming in F#, teaches you how to use control structures, more idiomatic .NET with F#, and interfacing with C# and generics.

Chapter 5, Asynchronous Programming, goes through the asynchronous programming model in F#, with a bit of cross-referencing or comparison drawn with the C# world.

Chapter 6, Type Providers, talks about some of the most common type providers, and additionally, also looks at the Query build that will help write LINQ-like queries for our custom collections.

Chapter 7, Web Programming in F#, teaches you how to build web servers using some of the most common .NET libraries as well as how you can write code for the browser in F# using WebSharper or Fable.

Chapter 8, Application Development in F#, explains how to write cross-platform desktop applications in F# using Fable and the Github Electron project.

Chapter 9, Testing in F#, teaches you how to write unit tests in F# with popular tools, and the advantages the language offers for this.

Chapter 10, Distributed Programming in F#, delves into using F# to implement the actor model popularized by Erlang, in order to write more robust software using decoupled actors that can run on different machines over a network and heal themselves in the eventuality of failure.

What you need for this book

All you need for this book is a computer that can comfortably run the following software applications: An F# IDE like Visual Studio 2015 (with Visual F# Power Tools), Visual Studio for Mac or Visual Studio Code with the Ionide extension.

Who this book is for

If you are a C# developer with a basic knowledge of F# and want to explore the functional programming paradigm further to master your F# skills, then this book is for you.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The class overrides a ToString function from the base class."

A block of code is set as follows:

 let x = 20 
    if not (x < 10) then 
        printfn "x is greater than 10"

Any command-line input or output is written as follows:

> let p = new Point(10, 20);; 
val p : Point = Point 10, 20

New terms and important words are shown in bold. 

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Mastering-FSharp. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.