Stefania Loredana Nita and Marius Mihailescu
Haskell Quick Syntax ReferenceA Pocket Guide to the Language, APIs, and Library
Stefania Loredana Nita
Bucharest, Romania
Marius Mihailescu
Bucharest, Romania
ISBN 978-1-4842-4506-4e-ISBN 978-1-4842-4507-1
© Stefania Loredana Nita and Marius Mihailescu 2019
Standard Apress
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.
Introduction

Haskell is a functional programming language, named after mathematician Haskell Brooks Curry, who made important contributions to mathematical logic that were used as the basis for functional programming. The first version, Haskell 1.0, was released in 1990, and the latest version is Haskell 2010, released in July 2010.

These are the main characteristics of Haskell:
  • It is purely functional, which means that all functions written in Haskell are also functions in the mathematical sense. The variables are immutable; in other words, they cannot be changed by any expression. Haskell does not contain statements or instructions, just expressions that are evaluated.

  • It is lazy, meaning the expressions are evaluated when it is really necessary. Combined with the purity of Haskell, you can create chains of functions, which improves performance.

  • It is statically typed, which means that every expression has a type, established at compile time.

  • It enables type inference through the unification of every type bidirectionally. This is beneficial, because you do not need to write specifically every type in Haskell, and if you need, you can define your own types.

  • Haskell is concurrent because it works with effects.

  • It has many open source packages.

From these features, you can identify some of the advantages of using Haskell, listed here:
  • The quality of the code is high.

  • You can work with abstract mathematical concepts.

  • The type system is flexible.

  • Errors are kept to a minimum.

  • The syntax is optimized and well-designed.

  • It brings a good performance due to concurrency.

In this book, we will start with simple topics and increase the level of complexity with each chapter. All the chapters contain examples to illustrate each specific subject covered.

Source Code

You can download this book’s source code by navigating to https://www.apress.com/us/book/9781484245064 and clicking the Download Source Code button.

Structure of the Book

This book contains 26 chapters. Each chapter has its own goal of presenting the most important aspects of one topic that need to be taken into consideration during the learning process. The book highlights all the necessary elements of functional programming in Haskell that you’ll need to start developing programs with it.

The structure of the book is as follows:
  • Chapter 1 : Functional Programming. This chapter provides a short introduction to functional programming.

  • Chapter 2 : Static Typing. This chapter presents in a practical manner the elements necessary to understand how you can use static typing.

  • Chapter 3 : GHC. This chapter contains the basic ideas of the Glasgow Haskell Compiler, an open source native code compiler for the functional programming language. We show several examples of how you can use GHC.

  • Chapter 4 : Types. This chapter goes through all the details necessary to understand how types work and how you can use them.

  • Chapter 5 : Tuples. The discussion in this chapter focuses on how tuples are represented and implemented. We discuss their performance, and through different examples we show how they are best used.

  • Chapter 6 : Lists. The chapter demonstrates how lists can be implemented and their basic operations (finding/searching, adding, and deleting). In this chapter, you will learn how to modify a list or its elements and how to work with lists and I/O operations.

  • Chapter 7 : Functions. The chapter presents the main elements necessary to construct functions and how it is possible to work with them.

  • Chapter 8 : Recursion. The chapter shows the necessary elements for developing applications using recursion and the optimal way of doing it.

  • Chapter 9 : List Comprehension. The chapter shows how syntactic “sugar” such as list comprehension can be used in Haskell applications, which are designed as special applications.

  • Chapter 10 : Classes. The chapter discusses how classes are defined, gives examples, and shows how data can be structured and modeled with the help of classes.

  • Chapter 11 : Pattern Matching. This chapter covers some of the coolest syntactic constructs and how pattern matching can be applied.

  • Chapter 12 : Monads. This chapter covers monads and what they are. The examples shown demonstrate how programs, both generic and declarative, can be structured logically. The chapter shows how generic and declarative data types are transformed with the help of higher-order functions.

  • Chapter 13 : Monad Transformers. This chapter contains some examples that show the power of monad transformers, with the goal of building computations with effects.

  • Chapter 14 : Parsec. The chapter shows how you can use a parsec, an industrial-strength tool.

  • Chapter 15 : Folds. The chapter illustrates through examples the family of higher-order functions that process a data structure in some order and how the return value is constructed.

  • Chapter 16 : Algorithms. The chapter presents examples of algorithms and goes through different categories of algorithms such as currying, folds, design patterns, dynamic programming, and so on.

  • Chapter 17 : Parsings. The chapter demonstrates how you can use different methods of parsing.

  • Chapter 18 : Parallelism and Concurrency. In this chapter, we discuss about parallelism and how to speed up the code by making it run on multicore processors.

  • Chapter 19 : Haskell Pipes. This chapter includes practical examples of I/O operations and Haskell pipes.

  • Chapter 20 : Lens. The chapter discusses the Control.Lens package and how to use it to obtain maximum results with your Haskell program.

  • Chapter 21 : Lazy Evaluation. This chapter shows the main way to evaluate a Haskell program.

  • Chapter 22 : Performance. The chapter discusses techniques for increasing the performance of Haskell programs.

  • Chapter 23 : Haskell Stack. The chapter discusses the Stack tool and how you can use it in projects. It also discusses its dependencies.

  • Chapter 24 : Yesod. Yesod is a free and open source web framework developed for Haskell for productive development. The chapter gives a quick overview of Yesod and how to use it.

  • Chapter 25 : Haskell Libraries. The chapter shows how to use libraries and how to build new libraries.

  • Chapter 26 : Cabal. Cabal represents a common architecture for developing and building applications and libraries in Haskell. The chapter covers the packaging and destructions of software packages and how they can be used.

Table of Contents

Index 203

About the Authors and About the Technical Reviewer

About the Authors

Stefania Loredana Nita

has two B.Sc. degrees, one in mathematics (2013) and one in computer science (2016), from the Faculty of Mathematics and Computer Science at the University of Bucharest; she received her M.Sc. in software engineering (2016) from the Faculty of Mathematics and Computer Science at the University of Bucharest. She has worked as developer for an insurance company (Gothaer Insurance) and as a teacher of mathematics and computer science in private centers of education. Currently, she is a Ph.D. student in computer science in the Faculty of Mathematics and Computer Science at the University of Bucharest. She has been a teaching assistant at the same university and since 2015 has worked as a researcher and developer at the Institute for Computers in Bucharest, Romania. Her domains of interest are cryptography applied in cloud computing and big data, parallel computing and distributed systems, and software engineering.

 
Marius Mihailescu

received his B.Sc. in science and information technology (2008) and his B.Eng. in computer engineering (2009) from the University of Southern Denmark; he has two M.Sc. degrees, one in software engineering (2010) from the University of Bucharest and the second one in information security technology (2011) from the Military Technical Academy. His Ph.D. is in computer science (2015) from the University of Bucharest, Romania, with a thesis on the security of biometrics authentication protocols. From 2005 to 2011 he worked as a software developer and researcher for different well-known companies (Softwin, NetBridge Investments, Declic) in Bucharest, Romania (working in software and web development, business analysis, parallel computing, cryptography researching, and distributed systems). From 2012 until 2015 he was an assistant in the informatics department at the University of Titu Maiorescu and in the computer science department of the University of Bucharest. Since 2015, he has been a lecturer at the University of South-East Lumina.

 

About the Technical Reviewer

Germán González-Morris

is a polyglot software architect/engineer with 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 about an application container (WebLogic) and various programming languages (Haskell, TypeScript, WebAssembly, math for coders, and regexp). You can find more details on his blog ( https://devwebcl.blogspot.com/ ) or on Twitter ( @devwebcl ).

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

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