F# Deep Dives
Edited by Tomas Petricek and Phillip Trelford
Copyright
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact
Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email:
orders@manning.com2015 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.
Recognizing the importance of preserving what has been written, it is Mannings policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15% recycled and processed without the use of elemental chlorine.
| Manning Publications Co.20 Baldwin RoadPO Box 761Shelter Island, NY 11964 | Development editor: Cynthia KaneCopyeditor: Liz WelchProofreader: Tiffany TaylorTypesetter: Dennis DalinnikCover designer: Marija Tudor |
ISBN 9781617291326
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 MAL 19 18 17 16 15 14
Brief Table of Contents
Table of Contents
Contributors
Chris Ballard |
Keith Battocchi |
Colin Bull |
Chao-Jen Chen |
Yan Cui |
Johann Deneux |
Kit Eason |
Evelina Gabasova |
Dmitry Morozov |
Tomas Petricek | , appendix |
Don Syme |
Phillip Trelford |
Preface
For the last two years, interest in F# and functional-first programming has been growing steadily. More than 10 books about F# are now on the market, more than one new user group has appeared somewhere in the world every month during the last year, and the number of members of and visitors to the F# Software Foundation has been increasing at a steady rate.
Many people become interested in F# because they hear about the benefits that functional-first programming gives you: the F# type system mostly removes the need for null checking and other invalid states; avoiding a mutable state and its declarative nature makes it easier to understand your programs; and the agent-based programming model simplifies concurrency. These are all nice facts about F#, but how do you put them into practice?
We provide the answer with this book. Rather than introducing F# language features using simple, toy examples, we worked with F# experts who have hands-on F# experience. We asked each of them to write a chapter based on a real scenario that they solved with F#. Each chapter is a case study documenting not just the source code written, but also the authors approach to solving the problem, how it integrates with the broader ecosystem, and the business benefits gained from using F#.
This means the narrative of the book isnt built along the technical aspects of the F# language. Instead, we focus on the business benefits you get from using F# in practice. Although we look at diverse domains ranging from game development to financial systems and social network analysis, there is still a common theme. The four key concepts youll see repeated over and over are time-to-market, taming complexity, correctness, and performance. How these concepts fit with actual business problems is covered in detail in , which was coauthored by lead F# language designer Don Syme.
Acknowledgments
As the editor of this book, but author of only part of it, I feel slightly uncomfortable writing the acknowledgements section, because this book would not exist without the authors of the individual chapters, and they deserve most of the credit and thanks. In other words, if the book feels inconsistent, its because of me; but if you like the content, you should thank the individual authors! You will find their names and bios at the end of each of the chapters. I would also like to thank my co-editor, Phil, who helped to shape the book and find an interesting group of contributors.
The main theme of this section is patience. Im grateful to everyone at Manning for their continued support despite the numerous delays as we worked on this book. I would also like to thank all the readers of the MEAP (Manning Early Access Program) version of this book who did not ask for a refund and believed that they would eventually receive a finished book. It took a long time, but its finally here!
As I said, most of the acknowledgments should be dedicated to the authors of the individual chapters and the great people around them who supported them while they were writing (and hopefully made my continuous nagging bearable!). Thank you all for letting your friends, husbands and wives, or fathers and mothers work on this book for so many nights and weekends!
I want to thank everyone at Manning who made this book possible: Mike Stephens, who helped start the project; Marjan Bace, who trusted us; Cynthia Kane, who kept the project alive during crucial times; and the many individuals who worked on the book during production, including copyeditor Liz Welch, proofreader Tiffany Taylor, typesetter Dennis Dalinnik, and many others who worked behind the scenes. Special thanks to Mark Seemann for his careful technical proofread of the book shortly before it went into production.
Finally, the book also benefited greatly from the feedback that was provided by the reviewers of early drafts. This includes Adrian Bilauca, Christopher Reed, Dave Arkell, David Castro Esteban, Dennis Sellinger, Jeff Smith, Jon Parish, Jonathan DeCarlo, Kostas Passadis, M Sheik Uduman, Mark Elston, and Pasquale Zirpoli. Thank you!
T OMAS P ETRICEK
About this Book
Have you looked into F# briefly, found it interesting, and felt that your business could benefit from using itbut you arent sure how to best use F# in practice, how to approach problems from the functional-first perspective, and how to convince your colleagues that F# is the right choice? If youre nodding while reading these words, then youre holding the right book!
In this book, weve tried to answer many of the difficult questions that you have to answer when you learn F# and want to use it in practice. What does your business gain from adopting functional-first programming? What are some of the areas where people have succeeded with F#, and what is the best strategy for integrating F# with the rest of your ecosystem? And how do F# developers and architects think when they approach a problem?
These arent easy questions, and there isnt a single answer. So rather than seeking just 1 answer, we collected 11 answers from different people who come from different backgrounds and different industries. If youre working in a particular industry, then youll likely find a chapter that is close to what youre doing, and you can start reading the book from there, focusing on the topic(s) that are close to you. That said, none of the chapters is specific to a single industry or a single problem. Each chapter has a more general takeaway point that is interesting even if youre coming from elsewhere.