Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
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
€36.99
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
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Fahad Profile Icon García-Caro Núñez
Arrow right icon
€36.99
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
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Mastering F#

Chapter 1. Getting Started in F#

F# is a functional first language in the .NET family and is a derivative of the Meta-Language (ML) family of languages. It shares many features with dialects of ML, which originally derives from the classical ML language designed by Robin Milner in 1973 at the University of Edinburgh. As a .NET language, F# code compiles to Microsoft Intermediate Language (MSIL), which runs on top of Common Language Runtime (CLR).

In this chapter, we will cover the following topics:

  • The key features of F#
  • The functional and imperative languages
  • Using F# with Visual Studio
  • Basic expressions in F#

Key features of F#

The following are some points that Distinguish the F# language from other .NET languages:

  • F# is a functional first language, which means that functions are treated as first-class citizens, but it also provides ways to work with other paradigms, such as object-oriented programming (OOP) (as in C#).
  • Unlike other languages, such as C#, which mixes expressions (language constructs returning a value) and statements (constructs that don't return a value), F# is an expression-based language. You can think of every syntax construct in F# as a small function.
  • F# is a strongly-typed language, meaning that the type of every expression in the program is determined at compile time. This allows the compiler to make verifications in our code and enables great tooling support, such as autocompletion, refactoring, and so on.
  • Additionally, F# has a very strong type inference mechanism to infer types for the expressions in a program. This removes much of the verbosity usually associated with strongly-typed languages.
  • The .NET generics' type system is baked into the core of F#. For example, the programmer doesn't have to specify the functions to be generic; if the F# type system infers the variables can be generic (provided it is implemented that way), the function becomes generic. This makes it easier to write polymorphic code, that is, functions that can be reused with different types.
  • F# has a module system that allows data structures to be specified and defined abstractly. Unlike C# namespaces, F# modules can contain functions that help you separate data (types) from logic (functions in modules).
  • F# implements a pattern matching mechanism, which allows controlling conditions based upon structural similarities; whereas, other languages only allow value matching as in IF...ELSE statements in C#.

Functional and imperative languages

Imperative languages usually modify the state of a variable for most operations. This makes it more difficult to reason about our program, particularly when different parts of our code change values that are globally accessible. When a piece of code modifies a value outside its scope, we talk about side-effects (this may also include other state modifications, such as file or console operations). OOP tries to tame side-effects by encapsulating state. However, this is not always a complete solution, as objects often develop tight and complex dependencies with each other that are still difficult to reason with.

Functional languages solve this problem using pure functions. Pure functions are closer to the mathematical ideal of functions, in the sense that they don't have side-effects (don't change state outside their scope) and always produce the same output given the same input. Pure functions are easier to refactor and reason with because their output is predictable, and can be used as building blocks to write large programs with different techniques of function composition.

F#, as described, is a functional-first language, but the language can also deal with unavoidable side-effects such as file or logging operations.

To compare F# with a more imperative language, we can take the example of a Fibonacci sequence generator, as follows:

public static int Fibonacci(int n)
{
    int a = 0;
    int b = 1;
    // In N steps compute Fibonacci sequence  iteratively.
    for (int i = 0; i < n; i++)
        {
            int temp = a;
            a = b;
            b = temp + b;
        }
            return a;
}

let rec fib n =
if n < 2
then 1
else fib (n - 2) + fib (n - 1)

Note

For illustration purposes, C# in procedural style is used. It is also capable of more functional implementations, such as Language Integrated Query (LINQ). Also, performance is not taken into consideration.

In an imperative language, the algorithm is normally implemented as a loop, and progress is made by modifying the state of the variables used in the loop.

In F#, the Fibonacci sequence is implemented using recursion. The let keyword, which defines the function, and the rec keyword, which specifies the function, can be called recursively. Using recursion, we are parameterizing the state (we will pass the updated values as parameters to the next call) so we do not need to use mutable variables.

However, please note that programs exclusively using a functional style can have performance problems. In this book, we will take an intermediate approach of using imperative code when necessary.

F# and integrated development environments

F# is very well integrated into Visual Studio 2010 and higher versions. This is a first-class language along with C# and VB.NET. There is also support for F# in cross-platform integrated development environments (IDEs) such as Xamarin Studio, the Ionide extension for Visual Studio Code, or Atom. See http://fsharp.org/ for more information.

Using F# with Visual Studio

Visual Studio includes the default project templates for F#. We can look for Visual F# and see a list of templates available.

Using F# with Visual Studio

Note

The screenshots in this book have been taken with Visual Studio 2012, but they should be very similar to other Visual Studio versions.

For example, let's create an F# console application called FSharpHelloWorld and understand the different aspects of an F# project. The Solution Explorer lists the following files:

Using F# with Visual Studio

Open Program.fs and view the contents; it has very low-ceremony code to run the console application, which is as follows:

    [<EntryPoint>] 
    let main argv = 
        printfn "%A" argv 
        0 // return an integer exit code 

If you are a C# developer, some elements of this little program may surprise you. For example, the EntryPoint attribute indicates which function must be run when a console application starts. Also, as mentioned in the preceding code snippet, every expression in F# returns a value, so there is no need for an explicit return keyword.

Modify the printfn statement to include "Hello World", as shown in the following code snippet:

    [<EntryPoint>] 
    let main argv = 
        printfn "Hello from F# :)" 
        0 // return an integer exit code 

F# project structure

F# projects follow a top-to-bottom structuring of program files. Unlike C# or VB.NET, this is the very first thing to understand to organize files and folders with F#.

Note

Folder management is not available in F# within Visual Studio by default; you will need to install the Visual F# Power Tools extension for that.

You will learn by adding some files to the hello world project, as follows:

  • Add a new F# Employee.fs source file to the hello world project
  • The Employee.fs file gets added to the end of the project
  • Press ALT + the up arrow, or right-click and move up or down, to arrange the file as shown in the following screenshot:

F# project structure

F# Script File

With F#, you can not write projects (.fsproj) containing module files (.fs), but also scripts (.fsx). These are single-file projects that are useful to write short programs, automation tasks, and so on.

F# Script File

With F# Script File, we will get the following features:

  • Full IntelliSense support
  • Loading external files or .NET libraries
  • Prototyping code that can easily be moved to a real codebase with minimal or no code changes
  • An F# interactive window in Visual Studio that can be used to quickly test parts of the code from your F# script or normal F# files

Using the F# Interactive window

The F# Interactive window provides a read-evaluate-print-loop (REPL) to evaluate your expressions without having to create, build, and run an F# project. This is very useful for developers to work in exploratory mode.

The following are the two ways to use the F# Interactive window:

  • Visual Studio
  • Command line

The Visual Studio interactive window

To access the F# Interactive window from the menu, navigate to View | Other Windows | F# Interactive.

The Visual Studio interactive window

Note

To evaluate an expression directly in the interactive window, terminate the code with double semicolons (;;). This is not necessary in the F# source code.

Use the F# script files to quickly check a piece of code. We will now check this feature by writing a square root and a Fibonacci function. Add the following functions to a script file:

    let sqr x = x * x 
    let rec fib n = 
        if n < 2 then 1 
        else fib (n - 2) + fib (n - 1) 

After adding the preceding code snippet in the script file, perform the following steps:

  1. Right-click on the selected code and select Execute In Interactive or press Alt + Enter.

    The Visual Studio interactive window

  2. This will send the functions to the F# Interactive window. The window then displays the signature of the functions. Note that the syntax for signatures is a bit different from what we saw before. In this case, it means both functions accept and return an int value.
  3. We can call the functions directly in the interactive window by applying an int argument to the name of the function, as shown in the following screenshot:

    The Visual Studio interactive window

There are some idioms that you will need to be familiar with when using F# Script File or the F# Interactive mode.

Idioms

Description

#load

This loads a script/F# file. For example, refer to the following piece of code:

#load "sample.fs"   
#load "sample.fsx"   

#I

This refers to a folder to load the assemblies in. For example, refer to the following piece of code:

#I @"C:\Program Files   (x86)\Reference    Assemblies\Microsoft\Framework\.NETFramework\v4.0"   

#r

This refers to the assembly to load from the referenced folder. Usually, this is used in conjunction with #I.

For example, refer to the following piece of code:

#I @"C:\Program Files   (x86)\Reference    Assemblies\Microsoft\Framework\.NETFramework\v4.0"   
#r "presentationcore.dll"   

#help

This displays information about available directives.

#quit

This terminates the interactive session.

#time [on / off]

The #time directive toggles whether to display performance information or not. When it is enabled, F# measures real-time, CPU time, and garbage collection information for each session of code that is interpreted and executed.

The FSI interactive window

FSI interactive shell is a simple console app that is bundled with the F# installation. To open FSI, perform the following steps:

  1. Open a terminal window.
  2. Type fsi to log in to the FSI session.
  3. Try some simple code to evaluate.

    The FSI interactive window

Note

In non-Windows platforms, the command to start the F# interactive session is fsharpi.

When you see code preceded by > in this book, it means that the line is supposed to be evaluated directly in an F# interactive session.

Basic values

In F#, every valid value must have a type, and a value of one type may not be bound to a value of another type. We will declare values in F# using the let keyword. For example, refer to the following piece of code:

    // variable expression 
    let x = 10 
    // function expression 
    let add a b = a + b 

As you learn F#, you will initially spend a lot of time getting the F# type checker to accept your programs. Being patient and analyzing the results with the F# type checker eventually helps you program better; you will later realize that the type checker is your best friend. Some rules about type checking are as follows:

  • Every expression has exactly one type
  • When an expression is evaluated, one of the following two things can happen:
    • It could evaluate to a value of the same type as the expression
    • It may raise an exception or error (this is actually a side-effect)

The let bindings can also be nested as follows:

    let z = 
        let x = 3 
        let y = 4 
        x + y 

Note

Note that the inner let bindings are placed to the right of the outer let bindings. This is important because the F# compiler determines scope by indentation.

When an expression is bound to a value in a let binding, the value can be used within the body of let (its scope). If a value with the same name was declared previously, the previous definition is overridden with the new definition; this is called shadowing and is often used in F# instead of value mutation. Let's consider the following example:

    let test() = 
        let x = 5 
        do 
            let x = 10 
            printfn "%i" x // prints 10 
        x // returns 5 

Here, we are not reassigning 10 to the previously declared x value. Instead, we are effectively creating a new value, as you can see, because in the outer scope x is still 5.

If needed, it is still possible to modify values in F#. For that, we will need to use the mutable keyword, as shown in the following piece of code:

    let test() = 
        let mutable x = 5 
        do 
            x <- 10 // assignment 
            printfn "%i" x // prints 10 
        x // returns 10 

Getting started with functions

Anonymous functions, or lambdas, are defined with the fun keyword, followed by a sequence of parameters with the -> separator, and then the body of the function expression. The following is an example function to add two numbers:

> let sum = fun a b -> a + b;; 
val sum : a:int -> b:int -> int 

Note

A shortcut for the preceding code is let sum a b = a + b.

The type for sum is int -> int -> int. Like other functional languages, this means that arguments are curried. Think of sum as a function returning another function, which can be partially applied, as we will see in the following section.

Partially applied functions

In F#, and other similar functional languages, functions actually have only one input and output. When we declare a function with multiple arguments, we are actually building functions that return other functions until the desired output is obtained. In the following code snippet, the two functions are effectively identical:

> let sum = fun x y z -> x + y + z;; 
val sum : x:int -> y:int -> z:int -> int  
> let sum' = fun x -> fun y -> fun z -> x + y + z;; 
val sum' : x:int -> y:int -> z:int -> int  

Note

The apostrophe is a valid character in F# and it is often used to mark values with a slight modification from a previously existing one.

The application of lesser arguments than the arity (the total number of arguments a function can accept) is called a partial application.

> let sum a b = a + b;; 
> let incr_by_ten = sum 10;; 
> incr_by_ten 5;; 
val it : int = 15 

Partial functions also help in writing concise code with F# pipeline operators, as shown in the following code:

    let res1 = List.map (fun x -> x + x) [2; 4; 6] 
    let res2 = List.filter (fun x -> x > 5) res1 

The preceding code can be rewritten in a more expressive way using the pipe (|>) operator:

    [2; 4; 6] |> List.map (fun x -> x + x) |> List.filter (fun x -> x > 5) 

Note

In F#, infix operators can be declared the same way as functions; the only difference is that we will surround them with parentheses in the declaration (for example, let (++) x y = (x + y) * 2) and then use them in the middle of the arguments (for example, 5 ++ 3).

For C# and VB.NET users, this is much like the continuation style programming with LINQ functions. In LINQ, you will normally pipeline a sequence of function calls, as follows:

    var listOfItems = someItems.Select(x => x.Name).OrderBy(x => x); 

However, for this the type returned by the first method needs to implement the method we want to call next. This is not a limitation when using the pipe operator.

Note

It is also possible to declare functions in a more similar way to languages such as C# (for example, let sum (x, y) = x + y), but there is an important difference-these functions take a single tuple argument. We will discuss tuples in Chapter 2, Functional Core with F#.

Recursive functions

In functional languages, recursion is used to express repetition or looping. For example, the Fibonacci sequence generator can be written as follows:

    let rec fib n = 
        if n < 2 then 1     
        else fib (n - 2) + fib (n - 1) 

We use the rec keyword to define a function as recursive. This is necessary to help the F# type checker infer the types of the function signature.

Every time a function is called recursively, a new routine is added to the call stack. As the call stack is limited, we must be careful not to overflow it. To prevent this, the compiler of F# and most functional programming languages implements an optimization called tail-call, which basically compiles down to a while loop. To enable this optimization, we will need to make sure the recursive call is the last expression in the function.

    // tail-recursion 
    let factorial x = 
        // Keep track of both x and an accumulator value (acc) 
        let rec tailRecursiveFactorial x acc = 
            if x <= 1 then 
                // use the accumulator that has the final result 
                acc 
            else 
                // pass the accumulator + original value again to the recursive method 
                tailRecursiveFactorial (x - 1) (acc * x) 
        tailRecursiveFactorial x 1 

Higher-order functions

As functions are first-class citizens in functional languages, we can pass them as arguments to other functions. When a function takes another function as an argument, we it a higher-order function. Let's consider the following example:

> let apply x f = f x 
val map : x:'a -> f:('a -> 'b) -> 'b 
> let sqr x = x * x 
val sqr : x:int -> int 
> let f = apply 5 sqr;; 
val f : int = 25

The preceding code snippets perform the following functions:

  • The apply function takes a function as a parameter and evaluates the function
  • We will declare a sqr function, which squares an int value
  • We will then call the sqr function through apply

Higher-order functions are very important to write composable and reusable code. Earlier, we saw List.map. Many of the functions in the Collections modules (List, Array, and Seq) accept functions as arguments so we can adapt their behavior to our needs.

Summary

In this chapter, we covered the basics of working with F# projects and used the interactive window to try out some basic constructs. Also, we saw a brief overview of different programming paradigms and the advantages of functional programming. In the next chapter, we will delve into some of the more powerful features of F#, such as record and union types as well as pattern matching.

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
Estimated delivery fee Deliver to Lithuania

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Estimated delivery fee Deliver to Lithuania

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

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
€18.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
€189.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
€264.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 110.97
Mastering F#
€36.99
F# 4.0 Design Patterns
€36.99
F# High Performance
€36.99
Total 110.97 Stars icon

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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela