Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Mastering F#
Mastering F#

Mastering F#: A comprehensive and in-depth guide to writing functional programs using F#

Arrow left icon
Profile Icon Fahad Profile Icon García-Caro Núñez
Arrow right icon
$19.99 per month
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.5 (2 Ratings)
Paperback Nov 2016 264 pages 1st Edition
eBook
$27.98 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Fahad Profile Icon García-Caro Núñez
Arrow right icon
$19.99 per month
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.5 (2 Ratings)
Paperback Nov 2016 264 pages 1st Edition
eBook
$27.98 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$27.98 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Mastering F#

Chapter 2. Functional Core with F#

As we have seen, F# is a functional-first language where we create functions and apply them. The result of the evaluation of one of these expressions is a value, and the execution of the program is the evaluation of all the expressions that comprise it.

In this chapter, we will cover the following topics:

  • F# types such as primitives, tuples, records, and unions
  • Pattern matching
  • Equality and comparison
  • Reference cells and mutability

F# primitive types

The data types defined in F# are mapped directly with CLR. The following table defines the F# primitive types:

Name

F# type

Suffix

Example

Boolean

bool

true/false

Character

char

'A'

Text string

string

"Hello World!"

Short

int16

s

15s

Unsigned short

uint16

us

100us

Integer

int

(none)

123

Float/ Double

float

(optional) e

2., 1.01, 1.10e10

Unsigned integer

uint32

u

123u

Long

int64

L

9999L

Unsigned long

uint64

UL

9999UL

Single

float32 or single

f, (optional) e

1.0f, 1.01f, 1.01e10f

Decimal

decimal

m

123m

Big integer

bigint

I

123I

Signed byte

sbyte

y

3y

Unsigned byte

byte

uy

5uy

Native integer

nativeint

n

123n

Unsigned native integer

unnativeint

un

123un

The unit type

The unit type is used to indicate the absence of a specific value, but formally describes a set that possesses only a single...

Immutability, type declarations, and strong type inference

F# strongly adheres to immutability, meaning that the values declared in the program cannot be modified once they are constructed. Immutability also makes the code more readable because updates in the program state are more visible; thus it is easier to detect which operations affect the state. There are also F#-specific types, such as tuples, records, discriminated unions, and option types, which are immutable in their nature. They exhibit the following characteristics:

  • Being immutable
  • Values cannot be null
  • Built-in structural equality and comparison

F# has pattern matching as a special feature (from the ML family). We will go through pattern matching over predefined types and then discuss the different structural types and how to construct values with them. In further chapters, we will take a look at all the F#-specific types and ways to declare and use them.

Pattern matching

Pattern matching is defined by a match expression, which...

Summary

In this chapter, we went through some of the functional aspects of F#, such as immutable data structures, structural equality, and pattern matching. We also explored as how we can write a more imperative style when needed, such as keeping internal state with reference cells or mutable data structures. In the next chapter, you will learn more about other data structures that are very important in F#: collections.

Left arrow icon Right arrow icon

Key benefits

  • Learn how to manage, run, and automate your servers using Puppet
  • Explore how to use F# to develop large-scale applications quickly and simply, and become more productive in today’s age of cloud computing and multi-core programming
  • This easy-to-follow guide is packed with real-world examples that will jump-start you with F# development on the .NET platform

Description

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.

Who is this book 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.

What you will learn

  • Understand the basics of F# and organize F# source code with Visual Studio
  • Work with F# data structures and create functional data structures in F# interoperate with C#
  • Build and use asynchronous programming patterns with F#
  • Create and use type providers that help perform data analysis from within Visual Studio
  • Develop applications with pure F# code in WPF or ASP.NET MVC
  • Find out how to perform distributed programming with ServiceBus or ZeroMQ
  • Visualize data with charts, and work with Excel and R language Type providers

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 30, 2016
Length: 264 pages
Edition : 1st
Language : English
ISBN-13 : 9781784393434
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Nov 30, 2016
Length: 264 pages
Edition : 1st
Language : English
ISBN-13 : 9781784393434
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 146.97
Mastering F#
$48.99
F# 4.0 Design Patterns
$48.99
F# High Performance
$48.99
Total $ 146.97 Stars icon
Banner background image

Table of Contents

10 Chapters
1. Getting Started in F# Chevron down icon Chevron up icon
2. Functional Core with F# Chevron down icon Chevron up icon
3. Data Structures in F# Chevron down icon Chevron up icon
4. Imperative Programming in F# Chevron down icon Chevron up icon
5. Asynchronous Programming Chevron down icon Chevron up icon
6. Type Providers Chevron down icon Chevron up icon
7. Web Programming in F# Chevron down icon Chevron up icon
8. Application Development in F# Chevron down icon Chevron up icon
9. Testing in F# Chevron down icon Chevron up icon
10. Distributed Programming in F# Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.5
(2 Ratings)
5 star 0%
4 star 0%
3 star 50%
2 star 50%
1 star 0%
pw242 Jul 29, 2020
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
It's clear that the book was not written by a native English speaker. One can normally figure out what the author means, but I found it took extra work on top of the difficulty of understanding the underlying subject. Imagine reading a technical document that has come through Google translate. It's workable, but not ideal.The content is present, but there are better resources available to learn it.
Amazon Verified review Amazon
Eik Christensen Feb 15, 2017
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
Reason for 2 stars is due to the formatting on kindle is really bad and with a programming language where the indentation of code is important, it does a poor job at making it work on a kindle. When going throu the code, i wasn't always sure if the code was belonging inside a function or outside the function.Other than that its a good reference book :-)
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.