Zum Hauptinhalt springen
Nicht aus der Schweiz? Besuchen Sie lehmanns.de

Soar with Haskell (eBook)

The ultimate beginners' guide to mastering functional programming from the ground up
eBook Download: EPUB
2023
418 Seiten
Packt Publishing (Verlag)
978-1-80512-256-2 (ISBN)

Lese- und Medienproben

Soar with Haskell -  Tom Schrijvers
Systemvoraussetzungen
33,59 inkl. MwSt
(CHF 32,80)
Der eBook-Verkauf erfolgt durch die Lehmanns Media GmbH (Berlin) zum Preis in Euro inkl. MwSt.
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

With software systems reaching new levels of complexity and programmers aiming for the highest productivity levels, software developers and language designers are turning toward functional programming because of its powerful and mature abstraction mechanisms. This book will help you tap into this approach with Haskell, the programming language that has been leading the way in pure functional programming for over three decades.
The book begins by helping you get to grips with basic functions and algebraic datatypes, and gradually adds abstraction mechanisms and other powerful language features. Next, you'll explore recursion, formulate higher-order functions as reusable templates, and get the job done with laziness. As you advance, you'll learn how Haskell reconciliates its purity with the practical need for side effects and comes out stronger with a rich hierarchy of abstractions, such as functors, applicative functors, and monads. Finally, you'll understand how all these elements are combined in the design and implementation of custom domain-specific languages for tackling practical problems such as parsing, as well as the revolutionary functional technique of property-based testing.
By the end of this book, you'll have mastered the key concepts of functional programming and be able to develop idiomatic Haskell solutions.


Build powerful software solutions and develop proficiency in Haskell, from understanding the foundational principles through to mastering advanced functional programming conceptsKey FeaturesLearn from an expert lecturer and researcher who knows all the ins and outs of HaskellDevelop a clear understanding of Haskell, from the basics through to advanced conceptsGet to grips with all the key functional programming techniquesPurchase of the print or Kindle book includes a free PDF eBookBook DescriptionWith software systems reaching new levels of complexity and programmers aiming for the highest productivity levels, software developers and language designers are turning toward functional programming because of its powerful and mature abstraction mechanisms. This book will help you tap into this approach with Haskell, the programming language that has been leading the way in pure functional programming for over three decades. The book begins by helping you get to grips with basic functions and algebraic datatypes, and gradually adds abstraction mechanisms and other powerful language features. Next, you ll explore recursion, formulate higher-order functions as reusable templates, and get the job done with laziness. As you advance, you ll learn how Haskell reconciliates its purity with the practical need for side effects and comes out stronger with a rich hierarchy of abstractions, such as functors, applicative functors, and monads. Finally, you ll understand how all these elements are combined in the design and implementation of custom domain-specific languages for tackling practical problems such as parsing, as well as the revolutionary functional technique of property-based testing. By the end of this book, you ll have mastered the key concepts of functional programming and be able to develop idiomatic Haskell solutions.What you will learnWrite pure functions in all their forms that is basic, recursive, and higher-order functionsModel your data using algebraic datatypesMaster Haskell's powerful type-class mechanism for ad hoc overloadingFind out how Haskell's laziness gets the job doneReconcile Haskell's functional purity with side effectsFamiliarize yourself with the functor, applicative functor, monad hierarchyDiscover how to solve problems with domain-specific languagesFind more bugs with Haskell's property-based testing approachWho this book is forIf you are a programmer looking to gain knowledge of Haskell who s never been properly introduced to functional programming, this book is for you. Basic experience with programming in a non-functional language is a prerequisite. This book also serves as an excellent guide for programmers with limited exposure to Haskell who want to deepen their understanding and foray further into the language.]]>

Preface


This book provides an introduction to functional programming in Haskell:

  • Functional Programming (FP) is one of the main programming paradigms, along with imperative programming and object-oriented programming. It uses functions as its core concept of computation – turning input into output in a predictable and context-independent way.While many non-FP languages also offer functions in some form, in FP, language functions truly have first-class status. They are not only computation but also data, which can be ferried around by other (higher-order) functions, dynamically assembled out of simpler functions, stored in data structures, or data containers themselves.
  • Haskell stands out among FP languages in that it unequivocally embraces the FP paradigm. Because it does not make any compromises for imperative programming, Haskell had to come up with entirely new solutions to tackle common programming problems that also turned out to be successful in solving next-level problems. This way, it has become an inspiration for the designers of other programming languages (both FP and non-FP) and libraries in those languages.

Besides being true to the principles of FP, Haskell is also renowned for its sophisticated static type system. This means that Haskell programs are automatically checked for particular kinds of mistakes (known as type errors) before they are run. Moreover, thanks to Haskell’s powerful type inference mechanism, programmers have to write little to no type annotations themselves. Taking all the preceding aspects of FP in Haskell into consideration, the common theme of this book is abstraction. It provides many mechanisms for abstraction and powerful examples of abstractions that allow us to converse and reason about common programming patterns, becoming more effective programmers when we (re)use them.

Who this book is for


This book is for all those who already have some programming experience and want to learn FP in Haskell:

  • If you are familiar with imperative or object-oriented programming, this book introduces you to the wonderful world of FP.
  • If you are already familiar with other FP languages, you will discover the unique Haskell language features, ideas, and programming style.
  • If you have outgrown your current programming language, are ready for a new challenge, or want to fall in love with programming all over again, your journey starts here.

What this book covers


Chapter 1, Functions, explains the core concept of FP – functions. It introduces function definitions and shows how functions are called. This includes an explanation of all the syntactic elements (types, type signature, function body, etc) and their role. Along the way, it also introduces a number of built-in types and functions.

Chapter 2, Algebraic Datatypes, introduces Haskell’s mechanism for user-defined types – Algebraic Datatypes (ADTs). We build up from simple forms of ADTs such as enumerations and records to their full generality, and we learn the different elements of ADT definitions – the type name, the data constructors, and their fields. We see how ADT values are created and how they are taken apart by pattern matching. Finally, we see how ADTs can be parameterized over other types.

Chapter 3, Recursion, presents the functional programming alternative to loops. Recursive datatypes are a natural mechanism to express data structures of arbitrary size, and recursive functions are the way to process these functions. We will focus in particular on structural recursion as a principled use of recursion but also cover alternative recursion patterns.

Chapter 4, Higher-Order Functions, explains how repeated patterns in function definitions can be abstracted over, notably by abstracting over higher-order parameters. Special attention goes to commonly used higher-order library functions such as map, filter, foldr, and foldl.

Chapter 5, First-Class Functions, covers a range of language features and mechanisms that facilitate function-oriented programming, where we program at the level of functions rather than plain values.

Chapter 6, Type Classes, presents Haskell’s unique mechanism for supporting ad-hoc overloading–type classes. It explains what ad-hoc overloading is and how functions give rise to polymorphic type signatures with type class constraints. Then, we will see how predefined type classes can be instantiated for user-defined types and how new user-defined type classes can be created. Finally, we cover several user-defined type classes and their use in standard libraries.

Chapter 7, Lazy Evaluation, reveals Haskell’s unique evaluation mechanism – lazy evaluation. It shows how lazy evaluation works and improves upon both call-by-value and call-by-name. Then, it shows how to use the strategy to your advantage by using lists as iterators that supply their elements on demand. Finally, the chapter also points out a pitfall of the mechanism – the build-up of thunks.

Chapter 8, Input/Output, explains Haskell’s unique way of interfacing with the outside world – its I/O mechanism. First, the chapter explains why the existing approach of other languages is problematic due to the lazy evaluation strategy and the language’s purity principle. Then, it presents the Haskell solution using the I/O type and >>=/return operators. Then, it introduces the do notation as a more user-friendly notation for I/O steps. Finally, it covers common I/O operations.

Chapter 9, Monoids and Foldables, introduces the notion of foldables. These are collections that support a similar range of frequently used operations. Along the way, we learn that Haskell has a mechanism to abstract over parts of types, called type constructors, and uses algebraic concepts such as semigroups and monoids to design highly general algorithms.

Chapter 10, Functors, Applicative Functors, and Traversables, leads us further into the hierarchy of type classes for type constructors. We will first consider functors – data structures that can be mapped over. Then, we will move on to applicative functors, which can merge multiple data structures, and finally, we will see traversables as data structures that can be mapped over with side effects.

Chapter 11, Monads, introduces the king of the type constructor hierarchy – monads. We will first cover two well-known examples of monads – the Maybe monad for failure and the state monad for state passing. Then, we will generalize from these examples and present the Monad type class. Finally, we will present a number of additional examples of monads.

Chapter 12, Monad Transformers, shows how the functionality of different monads can be combined into a single monad. The chapter covers the monad transformer mechanism and gives a range of commonly used instances. Then, it shows how applications can abstract over the implementation details of monads and monad transformers, with monad subclasses. Finally, we will see how the same monad transformers can be combined in different ways to achieve different behavior.

Chapter 13, Domain-Specific Languages, documents a powerful problem-solving technique that is appropriate when a range of problems have to be solved within the same problem area – domain-specific languages (DSLs) embedded in Haskell. First, we will see several examples of DSLs that are tailored to different problem areas. Then, we will focus on implementation techniques for DSLs. The most general and flexible approach is deep embedding. It contrasts with shallow embedding, which is a more lightweight and efficient technique.

Chapter 14, Parser Combinators, introduces parser combinators, a lightweight and convenient DSL in Haskell for parsing. It covers what parsing is and where it is used. Then, we will see a basic definition of parser combinators to get a good idea of how they work. From there, we will move on to the industrial-strength Parsec library. Finally, we see how to tackle common parsing problems with parser combinators.

Chapter 15, Lenses, presents an exciting approach to the mundane activity of data access in nested datatypes. First, it demonstrates the basic approach for records that is built into Haskell and identifies its disadvantages. Then, it presents the concept of lenses as a much more convenient alternative for both reading and updating fields. We will show that lenses not only compose trivially to reach deep into data structures but also can be used to seamlessly define virtual fields. Finally, we cover the main lens combinators provided by the well-known...

Erscheint lt. Verlag 22.12.2023
Sprache englisch
Themenwelt Mathematik / Informatik Informatik Programmiersprachen / -werkzeuge
Informatik Theorie / Studium Algorithmen
ISBN-10 1-80512-256-8 / 1805122568
ISBN-13 978-1-80512-256-2 / 9781805122562
Informationen gemäß Produktsicherheitsverordnung (GPSR)
Haben Sie eine Frage zum Produkt?
EPUBEPUB (Ohne DRM)

Digital Rights Management: ohne DRM
Dieses eBook enthält kein DRM oder Kopier­schutz. Eine Weiter­gabe an Dritte ist jedoch rechtlich nicht zulässig, weil Sie beim Kauf nur die Rechte an der persön­lichen Nutzung erwerben.

Dateiformat: EPUB (Electronic Publication)
EPUB ist ein offener Standard für eBooks und eignet sich besonders zur Darstellung von Belle­tristik und Sach­büchern. Der Fließ­text wird dynamisch an die Display- und Schrift­größe ange­passt. Auch für mobile Lese­geräte ist EPUB daher gut geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür die kostenlose Software Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür eine kostenlose App.
Geräteliste und zusätzliche Hinweise

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich
Die Welt der generativen KI verstehen

von Daniel Scholz

eBook Download (2025)
Carl Hanser Verlag GmbH & Co. KG
CHF 34,15
A Comprehensive Guide for Beginners: Unlocking Computational Thinking

von Cuantum Technologies LLC

eBook Download (2024)
De Gruyter (Verlag)
CHF 25,35