Alejandro Serrano Mena
Practical HaskellA Real World Guide to Programming2nd ed.
Alejandro Serrano Mena
Utrecht, The Netherlands
ISBN 978-1-4842-4479-1e-ISBN 978-1-4842-4480-7
© Alejandro Serrano Mena 2019
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

To Elena, and my two boys Quique and Julio, which bring me joy every single day.

Introduction

Functional programming is gathering momentum. Mainstream languages such as Java and C# are adopting features from this paradigm; and languages such as Haskell, Scala, Rust, Clojure, or OCaml, which embody functional programming from the very beginning, are being used in industry. Haskell is a noise-free, pure functional language with a long history, having a huge number of library contributors and an active community. This makes Haskell a great tool for both learning and applying functional programming.

Why You Should Learn Functional Programming

The rise in functional programming comes from two fronts. Nowadays, most applications are heavily concurrent or need to be parallelized to perform better. Think of any web server that needs to handle thousands of connections at the same time. The way you express the intent of your code using Haskell makes it easier to move from a single-thread application to a multi-threaded one at a negligible cost.

Apart from becoming more concurrent, applications are becoming much larger. You would like your development environment to help you catch bugs and ensure interoperation between all modules of your system. Haskell has a very strong type system, which means that you can express a wide range of invariants in your code, which are checked at compile time. Many of the bugs, which previously would be caught using tests, are now completely forbidden by the compiler. Refactoring becomes easier, as you can ensure that changes in your code do not affect those invariants.

Learning functional programming will put you in a much better position as a developer. Functional thinking will continue permeating through mainstream programming in the near future. You’ll be prepared to develop larger and faster applications that bring satisfaction to your customers.

Why You Should Read This Book

This book focuses both on the ideas underlying and on the practicalities of Haskell programming. The chapters show you how to apply functional programming concepts in real-world scenarios. They also teach you about the tools and libraries that Haskell provides for each specific task. Newcomers to functional programming will not be the only ones who will benefit from reading this book. Developers of Scala, Clojure, Lisp, or ML will be also able to see what sets Haskell apart from other languages.

The book revolves around the project of building a web-based strorefront. In each of the five parts, the focus is on a subsystem of this store: representing clients and products in-memory, data mining (including parallelization and concurrency), persistent storage, discounts and offers, and the general architecture of the application. The topics have been carefully selected for you to get a glimpse of the whole Haskell ecosystem.

Acknowledgments

These acknowledgments have been transported almost unchanged from the first to the second edition of the book. It is great to see how the people that supported you on your first writing adventure are still around and even more supportive than the first time.

First of all, I would like to acknowledge the great work of the technical reviewer and the editorial board. Their comments and suggestions have been extremely valuable for making the book better and more helpful. Jean-Philippe Moresmau did a great job in the first edition; this time Germán has taken his witness and the result is even better.

Writing a book is a very rewarding task, but it’s also quite a consuming one. For those times where the mood goes sour, there has not been anything better than the support that Elena brought to me. She was there while I was thinking, refining the examples, and reviewing the text one more time.

My family and my friends have also encouraged me the entire time, so a bit of thanks to all of them too. My parents Carmen and Julián deserve a very special mention: they’ve supported me during every single project, and as crazy as it may sound, throughout my whole life. They bought me the first computer I worked with, which was the computer I started programming in an old Visual Basic environment. It’s fair to say that without their help, you wouldn’t be reading this book.

Being surrounded by people who share your passion is the best way to stay motivated to learn and communicate what you know; my colleagues at Utrecht University are a prime example. Many ideas in this book have their roots in that department, and I feel honored to be part of it.

The entire Haskell community is wonderful. Having great mailing lists and IRC rooms full of (quite clever!) people always willing to help encourages you to be curious and to learn more. Every single library and compiler discussed in this book has been carefuly crafted by this community: they are the reason why Haskell is such a great language.

Table of Contents

Part I: First Steps
Part III: Resource Handling
Index 579

About the Author and About the Technical Reviewer

About the Author

Alejandro Serrano Mena

works as a lecturer and researcher at the Department of Information and Computing Sciences in Utrecht University. He is passionate about functional programming and has been coding in Haskell for personal and professional projects for more than 10 years. His current research focuses on how to increase the usefulness of type systems while decreasing their costs and their learning curve; his PhD dissertation discusses how to enhance error reporting in Haskell.

Alejandro has been very active in promoting functional languages, already since his college years. In addition to his duties as a lecturer, he participates actively in both academic and industry-oriented conferences, such as Lambda World and LambdaConf.

 

About the Technical Reviewer

Germán González-Morris

is a polyglot Software Architect/Engineer with more than 20 years in the field, with knowledge in Java(EE), Spring, Haskell, C, Python, and Javascript, among others. He works with web-distributed applications. Germán loves math puzzles (including reading Knuth) and swimming. He has tech-reviewed several books, including an application container book (Weblogic), as well as titles covering various programming languages (Haskell, Typescript, WebAssembly, Math for coders, and regexp). You can find more details at his blog site ( https://devwebcl.blogspot.com/ ) or twitter account ( @devwebcl ).

 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.111.70