38,39 €
A comprehensive and in-depth guide to writing functional programs using F#
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.
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.
This easy-to-follow guide with syntaxes will help you master the concepts of F#. Packed with in-depth examples of real-world uses, this book covers each topic in detail with a reference to C#, so you will understand the difference between the languages.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 314
Veröffentlichungsjahr: 2016
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2016
Production reference: 1251116
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78439-343-4
www.packtpub.com
Authors
Alfonso García-Caro Núñez
Suhaib Fahad
Copy Editor
Zainab Bootwala
Reviewer
Basel Wael Abu-Jamous
Project Coordinator
Izzat Contractor
Commissioning Editor
Ashwin Nair
Proofreader
Safis Editing
Acquisition Editor
Ajith Menon
Indexer
Tejal Daruwale Soni
Content Development Editor
Zeeyan Pinheiro
Graphics
Jason Monteiro
Technical Editor
Kunal Chaudhari
Production Coordinator
Shraddha Falebhai
Alfonso García-Caro Núñez is a linguist who, in recent years, changed the study of natural languages by the practice of their programming counterparts. He currently focuses on JavaScript and .NET development and has worked on developing mobile, web, and desktop applications for several industries, such as video games, education, green energy, or digital performances. He is also an international speaker who has presented at several conferences around the globe. His admiration for both the thriving JavaScript ecosystem and functional programming with F# made him look for a way to bring together both worlds, leading to the creation of Fable, an F# to JavaScript compiler that is attracting lot of attention from the community, and integrates the power and elegance of F# with the hundreds of JavaScript tools and libraries available.
I would like to say a big thank you to all the members of the incredibly supportive and welcoming F# community. Since my first timid steps into functional programming, I have been always encouraged to give my opinion and contribute to the development of the ecosystem and the language itself. Features and tools are important, but it is openness and collaboration that really makes you proud to belong to a community. Neither this book nor anything else in my life would have been possible without the care and love of my family. I dedicate this as well as all my work to the women of my life: my mother, wife, and daughter.
Suhaib Fahad is an entrepreneur and is running a startup; he is also an expert F# programmer and enthusiast, using F# in various domains within the products that he is building. He is extremely passionate about developing in functional languages and loves to engage with developers of different communities. He has also been researching and working with cloud scale applications since 2012. Fahad lives in Bangalore, the IT hub of India, with his wife and baby boy.
Dr Basel Abu-Jamous is a post-doctorate researcher in the area of bioinformatics at the University of Oxford. He is interested in the development of new computational algorithms that address bioinformatic questions with a special focus on tunable consensus clustering methods. He is also interested in the application of such methods in biology and medicine. For instance, he currently works in Dr. Steven Kelly’s laboratory within the C4 Rice Project that aims to improve photosynthetic efficiency in rice and thus to enhance crop yields. As such, the C4 Rice Project is one of the scientific Grand Challenges of the 21st century, involving the coordinated efforts of researchers from 12 institutions in eight countries.
Previously, while being in the group of Professor Asoke Nandi at Brunel University London, he worked closely with Professor David Roberts, the Professor of Hematology at John Radcliffe Hospital and the University of Oxford, to understand the genetic programs responsible for erythropoiesis, that is, the production of red blood cells in human bodies. He was also in collaboration with Professor Adrian Harris and Professor Francesca Buffa, experts in breast cancer at Churchill Hospital and the University of Oxford, to analyze genetic regulatory pathways in breast cancer tumors under hypoxia, that is, low levels of oxygen. Additionally, he was also involved in the analysis of data from other areas including baker’s yeast, malaria, and E. coli bacteria.
Dr Abu-Jamous received his Ph.D. from Brunel University London in July 2015 and was awarded the Dean’s Prize for Innovation and Impact in Doctoral Research in the area of electronic and computer engineering in December of the same year. In January 2015, he was appointed by Professor Nandi as a research assistant at Brunel University London, and in July 2016 he moved to the University of Oxford.
He has published eight journal papers, fourteen peer-reviewed full-length papers in international conferences, and a research monograph book (Abu-Jamous, Fa, and Nandi, Integrative cluster analysis in bioinformatics, John Wiley & Sons, 2015).
Dr Abu-Jamous would like to thank the C4 Rice Project for funding his current research, Brunel University London and the UK National Institute for Health Research (NIHR) for funding his Ph.D. degree and his previous post-doctorate research (NIHR grant reference number RP-PG-0310-1004). He would also like to thank his current and previous supervisors, Dr Steven Kelly and Professor Nandi, respectively, and all colleagues, collaborators, friends, and family for their support.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.
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.
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.
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.
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.
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.
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.
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:
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
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!
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 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.
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.
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.
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.
