logo Mon, 23 Dec 2024 09:48:36 GMT

Haskell in Depth


Synopsis


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!

Haskell in Depth is the perfect second book on Haskell. After a quick refresher on Haskell basics, this hands-on guide dives into examples and application scenarios designed to teach how Haskell works and how to apply it correctly. You'll learn about managing projects with Cabal and Stack, tackle error-handling and testing, and package programs and libraries for production deployment.

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

Vitaly Bragilevsky

Summary

Chapter 1: Getting Started

This chapter introduces the basics of Haskell, including type signatures, functions, and data structures. For example:

```haskell
mySum :: [Int] -> Int
mySum xs = sum xs

data Person = Person { name :: String, age :: Int }
```

Chapter 2: The Essence of Haskell

This chapter covers the core concepts of Haskell, such as laziness, immutability, and monads. For instance:

```haskell
fib :: Int -> Int
fib n = if n <= 1 then n else fib (n - 1) + fib (n - 2)

-- do notation for monads
do
x <- readLn :: IO Int
let y = x + 1
print y :: IO ()
```

Chapter 3: Types and Typechecking

This chapter delves into Haskell's powerful type system, including type classes, polymorphism, and type inference. Example:

```haskell
data Eq a => MyType a = MyType a

instance Eq Int where
(==) = undefined

instance Eq MyType where
(==) (MyType a) (MyType b) = a == b
```

Chapter 4: Functions

This chapter covers various aspects of functions in Haskell, including currying, function composition, and higher-order functions. For example:

```haskell
-- currying
myFunc :: Int -> Int -> Int
myFunc x y = x + y

-- function composition
(++) :: String -> String -> String
(.) :: (b -> c) -> (a -> b) -> (a -> c)
(++) . myFunc :: Int -> Int -> String

-- higher-order function
map :: (a -> b) -> [a] -> [b]
```

Chapter 5: Lazy Evaluation

This chapter explains lazy evaluation in Haskell and its implications. Example:

```haskell
-- Fibonacci sequence (lazy)
fibs :: [Int]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
```

Chapter 6: Recursion

This chapter covers different types of recursion in Haskell, including structural recursion and guarded recursion. Example:

```haskell
-- structural recursion on lists
length :: [a] -> Int
length [] = 0
length (x:xs) = 1 + length xs

-- guarded recursion
isEven :: Int -> Bool
isEven n
| n == 0 = True
| otherwise = isOdd (n - 1)
```

Chapter 7: Data Structures

This chapter introduces the commonly used data structures in Haskell, such as lists, trees, and maps. Example:

```haskell
data Tree a = Leaf a | Node (Tree a) a (Tree a)

tree :: Tree Int
tree = Node
(Node (Leaf 1) 2 (Leaf 3))
4
(Node (Leaf 5) 6 (Leaf 7))
```

Assassin's Creed Atlas

Assassin's Creed Atlas