Haskell School of Music 1.3-1.4

Posted on March 20, 2020

These are some points of reference and notes from the book the haskell school of music chapter one.

1.3 Computation by Calculation 1.4 Expressions and Values

1.3 Computation by Calculation

By Example
3 * (9 + 5)
3 * 14
42

Definition

simple x y z = x * y + z

Invocation

simple 3 9 5

Calculation

simple 3 9 5
 3 * (9 + 5) -- example of unfolding
 3 * 14
 42

So we can write simple 3 9 5 ⟹ 42
Which should be read as:

simple 3 9 5 evaluates to 42

 e ⟹ v -- reads e evaluates to v

This stuff is imlortant because musical programs usually have some kind of mathematical basis. Proof by calculation might be a tool used to connect problem specs with implementations. This may seem tedious but can be rewarding due to the confidence in the program and the ability to rule out errors earlier.

Exercise 1.1
Write out the calculation of: simple (simple 2 3 4) 5 6

simple (simple 2 3 4) 5 6
 simple (3 * (9 + 5)) 5 6
 simple (3 * 14) 5 6
 simple (42) 5 6
 42 * (5 + 6)
 42 * 11
 462

Exercise 1.2
Prove by calculation that: simple (a - b) a b ⟹ a² - b²

simple (a - b) a b
 (a - b) * (a + b)
+ ab - ab -
-

1.4 Expressions and Values