- Introduction to Functional Programming by Bird and Wadler (referred as ITFP)
- My solutions to (some) of the exercises in the book implemented in Haskell (PRs and comments are welcome!)
- ITFP 6.2.2, 6.2.3
- https://hackhands.com/lazy-evaluation-works-haskell/ (Haskell-specific)
In ghci
:
sqr (6 + 5) -- innermost vs outermost evaluation
fst (6, undefined) -- innermost vs outermost evaluation
let a = [1..] :: [Integer] ; let b = map (+ 1) a ; a !! 6; b !! 11 ; :sprint a ; :sprint b
- ITFP 6.2.1, 6.2.2
- ITFP 6.1, 6.2, 6.3
- http://dev.stephendiehl.com/hask/#strictness (Haskell-specific)
In ghci
:
:set -XBangPatterns
fst (1, undefined) -- 1
fst' (!a, !b) = a
fst' (1, undefined) -- 💥
length [undefined, 3, 4, 5] -- 4
-- 🤔 this didn't work in the live demo because I defined it as: g (!x:xs)= length (x:y:xs)
{ length' [] = 0; length' ((!x):xs)= length (x:xs) }
length' [undefined,3,4,5] -- 💥
- 6.3.3