Haskell in Depth
eBook - ePub

Haskell in Depth

Vitaly Bragilevsky

Partager le livre
  1. 664 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Haskell in Depth

Vitaly Bragilevsky

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

Haskell in Depth unlocks a new level of skill with this challenging language. Going beyond the basics of syntax and structure, this book opens up critical topics like advanced types, concurrency, and data processing. Summary Turn the corner from "Haskell student" to "Haskell developer." Haskell in Depth explores the important language features and programming skills you'll need to build production-quality software using Haskell. And along the way, you'll pick up some interesting insights into why Haskell looks and works the way it does. Get ready to go deep! Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the technology Software for high-precision tasks like financial transactions, defense systems, and scientific research must be absolutely, provably correct. As a purely functional programming language, Haskell enforces a mathematically rigorous approach that can lead to concise, efficient, and bug-free code. To write such code you'll need deep understanding. You can get it from this book! About the book Haskell in Depth unlocks a new level of skill with this challenging language. Going beyond the basics of syntax and structure, this book opens up critical topics like advanced types, concurrency, and data processing. You'll discover key parts of the Haskell ecosystem and master core design patterns that will transform how you write software. What's inside Building applications, web services, and networking apps
Using sophisticated libraries like lens, singletons, and servant
Organizing projects with Cabal and Stack
Error-handling and testing
Pure parallelism for multicore processors About the reader For developers familiar with Haskell basics. About the author Vitaly Bragilevsky has been teaching Haskell and functional programming since 2008. He is a member of the GHC Steering Committee. Table of Contents PART 1 CORE HASKELL
1 Functions and types
2 Type classes
3 Developing an application: Stock quotes
PART 2 INTRODUCTION TO APPLICATION DESIGN
4 Haskell development with modules, packages, and projects
5 Monads as practical functionality providers
6 Structuring programs with monad transformers
PART 3 QUALITY ASSURANCE
7 Error handling and logging
8 Writing tests
9 Haskell data and code at run time
10 Benchmarking and profiling
PART 4 ADVANCED HASKELL
11 Type system advances
12 Metaprogramming in Haskell
13 More about types
PART 5 HASKELL TOOLKIT
14 Data-processing pipelines
15 Working with relational databases
16 Concurrency

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Haskell in Depth est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Haskell in Depth par Vitaly Bragilevsky en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Programming Languages. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Éditeur
Manning
Année
2021
ISBN
9781638356929

Part 1. Core Haskell

We have many ways to start learning Haskell. You could come to this book from pure mathematics, or from theoretical underpinnings of functional programming, or from practical tutorials. Consequently, Haskell beginners have very different backgrounds. In this part, we’ll fly over the main building blocks for Haskell programs—namely, functions, types, type classes, modules, projects, and external packages—to make sure that we are on the same page before diving deeper into Haskell.
Even though there should be nothing new here for a junior Haskell developer, we’ll still talk about plenty of good practices ranging from using Text instead of String and looking for help to the pragmatics of using abstractions in Haskell. In the last chapter of this part, we’ll apply all the essential Haskell components to develop a standalone application that reports stock quote data.
  

1 Functions and types

This chapter covers
  • Using the Glasgow Haskell Compiler (GHC) interpreter to solve problems
  • Writing simple functional programs with pure functions and I/O actions
  • Using a type-based approach to design programs
  • Using GHC extensions for greater code readability
  • Efficient processing of text data
Functional programming differs significantly from imperative programming in the ways we design programs. Typing discipline adds some specifics, too. When we code in Haskell, we think in a special way: in terms of the given data and the desired processing results (with both sides expressed by types), instead of focusing on the steps we should execute to get those results.
In this chapter, we’ll see several examples of how to solve problems in the most Haskellish way:
  • By using GHCi REPL (read-evaluate-print-loop) without writing a program
  • By writing functions properly
  • By keeping pure functions separate from the I/O actions that communicate to users
  • By expressing ideas with types
We’ll also explore several of Haskell’s libraries for text processing, which is arguably one of the most common, albeit routine, tasks in software development nowadays.

1.1 Solving problems in the GHCi REPL with functions

Suppose we want to analyze the vocabulary of a given text. Many sophisticated methods for such analysis are available, but we will do something quite basic, though still useful:
  • Extract all the words from the given text file.
  • Count the number of unique words used (size of the vocabulary).
  • Find the most frequently used words.
This problem could be a component of a larger social media text analyzer. Such software could mine various pieces of information (ranging from level of education or social position to the risk of financial default) by analyzing texts people post on their social media pages.
Or, more likely, we’ve just gotten up in the middle of the night with a desire to explore the size of Shakespeare’s vocabulary. How many unique words did Shakespeare use in Hamlet ? How can Haskell functions help us to answer this question?
Example: Extracting a vocabulary in REPL
data/texts/hamlet.txt (The Tragedie of Hamlet)
We can solve problems in the GHCi REPL without writing programs.
We don’t have to write a program to use GHCi to compute the number of unique words used in a text file. We just need to fire up GHCi (let’s do that in the root folder of the hid-examples package), import a couple of modules for processing lists and characters, read the given file into a String, and then manipulate its content, as shown in the next code:
$ ghci ghci> :module + Data.List Data.Char ghci> text <- readFile "data/texts/hamlet.txt" ghci> ws = map head $ group $ sort $ words $ map toLower text ghci> take 7 ws ["&","'em?","'gainst","'tane","'tis","'tis,","'twas"]
The idea is to make the file’s content lowercase and then split it into a list of words, sort them, and remove repetitions by grouping the same words together and taking the first word in each group. Haskellers often check the types of functions they use right in GHCi as follows:
ghci> :type toLower toLower :: Char -> Char ghci> :type map map :: (a -> b) -> [a] -> [b] ghci> :type words words :: String -> [String] ghci> :type sort sort :: Ord a => [a] -> [a] ghci> :type group group :: Eq a => [a] -> [[a]] ghci> :type head head :: [a] -> a
If it’s hard to understand what is going on in the map head $ group $ sort $ words $ map toLower text expression, I’d advise writing out the specific types in place of the type variables in the type signatures. I’ll start here:
text :: String = [Char] toLower :: Char -> Char map :: (a -> b) -> [a] -> [b]
Here, map has the following type:
map :: (Char -> Char) -> [Char] -> [Char]
Consequently,
map toLower text :: [Char]
and so on.
The results we got in GHCi show that we’ve forgotten about leading and trailing punctuation, so we need to do some cleanup. The so...

Table des matiĂšres