Strong Typed Music ::

(Functional Programming, Music)

Level of abstractions in Functional paradigm


-> Data Types (Type and Data constructors)

-> Functions

-> High-order functions

Algebraic data type


Sum

Product

Exponential

Sum Type

ADT :: Sum Type is represented by logical operator OR

Product Type

ADT :: Product Type - represented by logical operator AND

a Pair has a value a and b of PitchClass type

Exponential type

ADT :: Exponential type -> represents some sort of transformation

Each ADT has its operator for the algebra realization


a | b = |a| + |b|


(a, b) = |a| * |b|


a -> b = |b| ^ |a|

Extra :: Types and their cardinalities

						
							|Void|  = 0
							|()|    = 1
							|Bool|  = 2
							-- Let`s check the cardinalities for ::
							type Product = |(Bool, Bool)|     = ???
							type Sum = |Either Bool Bool| = ???
							type Exponential = |(Bool -> Bool)|   = ???
						
					
Two different types A and B with the same cardinalities are isomorphisms between each other.

Function and function composition

Function Composition

							
								(.) :: (b -> c) -> (a -> b) -> a -> c
							
						

Higher order functions

						
							map :: (a -> b) -> [a] -> [b]
							-- maybe a little discussion about map and fmap 
						
					

but...

... a programmer's job ...

is ! as exciting

as a musician`s job ...

Looks pretty exciting, right?

¿Can they be combined?


¡Claro!

But first, let's refresh the theory of music

Intervals and chord construction

Music intervals

In music theory, an interval is the difference in pitch between two sounds.

Music intervals

Can be played


=> harmonic if the two notes sound simultaneously (chords)

=> melodic if they sound successively (melody)

Chord construction

The tertian method (third intervals) is the most common way of chrod creation in western music.

Triads in the key of C major

							
I -> C major = (C, E, G) (Ionian Mode)
IV -> F major = (F, A, C) (Lydian Mode)
V -> G major = (G, B, D) (Mixolydian Mode)

... so where is the bridge between FP and Music in the context of Haskell programming language?!

Euterpea :: A Haskell library for music creation
by Paul Hudak and Donya Quick

http://euterpea.com/
in hackage

Demo time I

TODO :: Show PitchClass, Pitch, Octave, Dur, playDev, (:+:), (:=:)
0. Play single C note
							
								playDev 2 $ (note qn (C,4) :: Music Pitch)
								playDev 2 $ c 4 qn
							
						

1. Play C major chord (C E G) in melodically (:+:)

2. Play C major chord (C E G) in simultaneously (:=:)

Demo time II

TODO :: High-order thinking (map, fold, reduce)

Classic 12 time/tact Blues chord progression

(I - IV - V)

But for Blues we need 7ths Sevenths Intervals for each chord

						
I -> C7 = (C, E, G, B)
IV -> F7 = (F, A, C, E)
V -> G7 = (G, B, D, F)
						
| C7 | C7 | C7 | C7 |
| F7 | F7 | C7 | C7 |
| G7 | F7 | C7 | C7 |


So the general rule for X7 chord construction is (1, M3, P5, m7)
¡Extra!

What I have (heard|found) about FP ::

"with functional programming I feel like there is also like more a 'let it flow' mindset"

"Good OOP is nothing more then FP in disguise."

"Design patterns are for fill the gap of the OOP abstractions lack."

"With the power paradigm you don`t need any framework for DI."

"In FP it is a common practice to compose and build computation pipelines and defer evaluation until the end."

"In FP it is easy, and expected, to factor out common functionality into generic, reusable components that can be composed each other."

"Data structures just are. They don`t do anything."

A good GROOVE for everyone

homework = (read the book, (play music | experimental with music), have fun)

Take aways ::

Functional programming is amazing!

Making music is a fun!


together = amazing fun!

Gracias | Danke | Dzięki | Thanks



FiN.

Pinchy: https://www.freepik.com/vipanee