Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Soar with Haskell

You're reading from   Soar with Haskell The ultimate beginners' guide to mastering functional programming from the ground up

Arrow left icon
Product type Paperback
Published in Dec 2023
Publisher Packt
ISBN-13 9781805128458
Length 418 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Tom Schrijvers Tom Schrijvers
Author Profile Icon Tom Schrijvers
Tom Schrijvers
Arrow right icon
View More author details
Toc

Table of Contents (23) Chapters Close

Preface 1. Part 1:Basic Functional Programming FREE CHAPTER
2. Chapter 1: Functions 3. Chapter 2: Algebraic Datatypes 4. Chapter 3: Recursion 5. Chapter 4: Higher-Order Functions 6. Part 2: Haskell-Specific Features
7. Chapter 5: First-Class Functions 8. Chapter 6: Type Classes 9. Chapter 7: Lazy Evaluation 10. Chapter 8: Input/Output 11. Part 3: Functional Design Patterns
12. Chapter 9: Monoids and Foldables 13. Chapter 10: Functors, Applicative Functors, and Traversables 14. Chapter 11: Monads 15. Chapter 12: Monad Transformers 16. Part 4: Practical Programming
17. Chapter 13: Domain-Specific Languages 18. Chapter 14: Parser Combinators 19. Chapter 15: Lenses 20. Chapter 16: Property-Based Testing 21. Index 22. Other Books You May Enjoy

The IO approach

In this section, we will see how Haskell overcomes the challenges of performing I/O, by means of an approach based on a special type called IO. The solution to the I/O problem in Haskell is a conceptual one. We split I/O into two parts. First, we make a description of what I/O actions should be performed, and in what order. This is akin to, for example, writing a recipe for chocolate mousse. The second part is to perform the actions described. This corresponds to making chocolate mousse by following the recipe.

Describing I/O

A description can be thought of as inert data; it just is and does not do anything itself. For example, a recipe is usually just text in a cookbook. We have seen an example of this already in the Expr datatype to describe arithmetic expressions:

data Expr = Lit Int | Add Expr Expr

When we write Add (Lit 5) (Lit 3), we just construct a data structure. No computation happens, and we do not get the value 8.

We have already constructed...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime