Values are irreducible, but applications of functions to arguments are reducible. Reducing an expression means evaluating the terms until you’re left with an irreducible value.
Haskell uses a non-strict evaluation (sometimes called “lazy evaluation”) strategy which defers evaluation of terms until they’re forced by other terms referring to them. p.84
Values are expressions, but cannot be reduced further. Values are a terminal point of reduction p.84
:load unloads previous function in GHCI (need to use cabal’s repl to load multiple functions) p.86
printInc2 n = let plusTwo = n + 2 in print plusTwo -- turns into printInc2' n = (\plusTwo -> print plusTwo) (n + 2)
which I guess means map let into \ (recall “\” means lambda in Haskell)
“This doesn’t work for every possible let expression as we don’t have a good way to translate let expressions that use free variables recursively5 into the lambda calculus. “
Exercises page 87
let x = 5 in x
5
let x = 5 in x * x
25
let id = \x -> x page 89 is the same as:
let id x = x
let a = b in c -- equivalent to (\a -> c) b (page 89)
c where a = b -- equivalent to (\a -> c) b (page 90)
x + 9001 where x = 10 (\x -> x + 9001) 10
Exercises Page 90
let x = 3; y = 1000 in x * 3 + y
m1009 = x * 3 + y where x = 3 ; y = 1000
let y = 10; x = 10 * 5 + y in x * 5
m300 = x * 5 where y = 10 ; x = 10 + 5 * y
let x = 7; y = negate x; z = y * 10 in z / x + y
mneg17 = z / x + y where x = 7; y = negate x; z = y * 1
Exercises Page 93
2 + 2 * 3 - 1 is the same as:
2 + (2 * 3) is the same as;
(2 + (2 *3)) - 1
7
(^) 10 $ 1 + 1 is the same as:
(^) 10 (1 + 1)
(^) 10 2
100
2 ^ 2 * 4 ^ 5 + 1 is the same as (since ^ as the highest operator precedence)
((2^2) * (4*5)) + 1
4 * 1024 + 1
4097
waxOn Exercises Page 94
let waxon = x * 5 where z = 7 ; y = z + 8 ; x = y ^ 2
Prelude> waxon 1125
formal parameter page 97 versus argument (bound parameter)
A function is a mathematical object whose capabilities are limited to being applied to an argument and returning a result. Functions can be described as a list of ordered pairs of their inputs and the resulting outputs, like a mapping
Operators are functions that are infix by default page 98