Haskell School of Music 2.1-2.2

Posted on April 18, 2020

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

2.2 Notes, Music, and Polymorphism 2.3 Convenient Auxiliary Functions 2.3.1 Example

2.2 Notes, Music, and Polymorphism

  • Constructing musical values as recursive data types allows us to deconstruct them print their structure and analyze them in a structure preserving way.
  • Control is used by the Modify constructor to annotate a Music value with a:
    • tempo change
    • transposition
    • phase attribute
    • instrument
    • key signature
    • custom label
  • AbsPitch is a type synonym for Int
  • KeySig constructors attach a key signature to a Music vlue
    • this is different from transposition

2.3 Convenient Auxiliary Functions

The following are defined in Euterpea for convenience


note :: Dur -> a -> Music a
note d p = Prim (Note d p)

rest :: Dur Music a
rest d = Prim (Rest d)

tempo :: Dur -> Music a -> Music a
tempo r m = Modify (Tempo r) m

transpose :: AbsPitch -> Music a -> Music a
transpose i m = Modify (Transpose i) m 
 
instrument :: InstrumentName -> Music a -> Music a
instrument i m = Modify (Instrument i) m
 
phrase :: [PhraseAttribute] -> Music a -> Music a
phrase pa m = Modify (Phrase pa) m
 
keysig :: PitchClass -> Mode -> Music a -> Music a     
keysig pc mo m = Modify(KeySig pc mo) m 
 

2.3.1 Example

A ii-V-I chord progression in a particular major key can be created by: - arranging a minor chord on the second degree of the major scale - followed by a major chord on the fifth degree - ending in a major chord on the first degree

This is expressed in haskell as
                                                          ⬇︎


t251 :: Music Pitch
t251 = let dMinor = d 4 wn :=: f 4 wn :=: a 4 wn
           gMajor = g 4 wn :=: b 4 wn :=: d 5 wn
           cMajor = c 4 bn :=: e 4 bn :=: g 4 bn
       in dMinor :+: gMajor :+: cMajor 

We can play this progression with the play function in GHCi
                                                                                                                  ⬇︎

> play t251