Haskell Cookbook
Build functional applications using Monads, Applicatives, and Functors
Yogesh Sajanikar
BIRMINGHAM - MUMBAI
Haskell Cookbook
Copyright 2017 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 author, 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: September 2017
Production reference: 1210917
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78646-135-3
www.packtpub.com
Credits
Author Yogesh Sajanikar | Copy Editor Karuna Narayanan |
Reviewer Fabian Linzberger | Project Coordinator Prajakta Naik |
Commissioning Editor Aaron Lazar | Proofreader Safis Editing |
Acquisition Editor Karan Sadawana | Indexer Francy Puthiry |
ContentDevelopmentEditor Siddhi Chavan | Graphics Abhinash Sahu |
Technical Editor Supriya Thabe | Production Coordinator Nilesh Mohite |
About the Author
Yogesh Sajanikar has received his bachelor's degree in Mechanical Engineering from Shivaji University, India, along with a gold medal and a master's degree in Production Engineering from the Indian Institute of Technology, Bombay, India.
Yogesh has an experience of more than 20 years, and he has extensively worked with Product Lifecycle Management ( PLM ) and Computer Aided Design ( CAD ) software development firms, and architected solutions for domains such as Construction and Shipping Domain.
Having hooked on to functional programming, he moved into the Finance domain and worked as an enterprise architect; he has also worked with Scala/F# and Haskell. Currently, he is working as a CTO for a startup. He has also started local Haskell meetups and has been an active participant in meetups and functional conferences.
Yogesh believes in the open source movement, and believes in giving back to the open source community.
I would like to sincerely thank my wife, Rashmi, for her constant encouragement and sacrifice; Atharva, my son, who has now decided to learn Haskell at an early age. I would like to take a moment to thank my mom, Geeta, and my late dad, Mukund, for enabling me in my lifes journey.
Last, but nonetheless, I would sincerely thank my friends and colleagues at work. In the end, all the thanks to the wonderful staff at Packt, especially Siddhi and Supriya, who worked really hard to bring this book to reality. Their perseverance and pursuance really helped me complete the book despite the delays on my side.
About the Reviewer
Fabian Linzberger is a functional programming enthusiast and practitioner. He discovered Haskell in 2010 and it has been his favorite programming language ever since. You can find some of his code (some of it in Haskell) on GitHub ( https://github.com/lefant/ ) or visit his personal homepage and check out his blog ( https://e.lefant.net/ ).
www.PacktPub.com
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 service@packtpub.com 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.
Why subscribe?
- Fully searchable across every book published by Packt
- Copy and paste, print, and bookmark content
- On demand and accessible via a web browser
Customer Feedback
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at https://www.amazon.com/dp/1786461358 .
If you'd like to join our team of regular reviewers, you can e-mail us at customerreviews@packtpub.com. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products!
Table of Contents
Preface
Functional programming has been gaining lot of momentum recently. We are seeing different paradigms of functional programming creeping into imperative languages such as C++, C#, and Python. There are languages such as Scala that try to offer best of both worlds, that is, object-oriented programming and functional programming.
As Haskell is a pure and non-strict language, and strictly separates pureness from effect-full computations, it really stands out among these languages. Its strong theoretical basis, such as an elaborate type system, combined with concise and expressive syntax, gives Haskell a unique flavor. It really helps in programming declaratively by specifying what rather than how! In this book, we will focus on practical aspects of the language.
Haskell Cookbook is meant for programmers who have a programming background. Most of the readers should be acquainted with an imperative language, such as Java/Python or C++.
This cookbook can be logically divided into two parts, the first five chapters serve as building blocks for programming in Haskell. These chapters cover syntactical and semantic details of the language by describing how to use and define functions and data types. In these chapters, we also cover type classes and the Functor, Applicative, and Monads concepts .
The last seven chapters will introduce you to the practical aspects of usage of Haskell and its rich set of libraries. These chapters will take you through containers in Haskell and backend development (developing with database) to frontend development (web framework). The last three chapters focus on advanced concepts, such as doing parallel and distributed programming in Haskell.