Assignment 2
Home Up Assignment 1 Assignment 2 Assignment 3 Assignment 4 Assignment 5 Assignment 6 Assignment 7 Assignment 8

 

More Music

Due: Monday Sept 22 at noon.

In this assignment you will start writing more interesting music applications, while becoming better Haskell programmers.  You should read through Chapter 5 in HSOM before starting.

Write programs to solve the following problems.  Place your solutions in a file called HW2.lhs that implements a module called HW2.

  1. Define a function repM :: Int -> Music a -> Music a such that repM n m repeats m n times.
  2. Using mMap, define a function:
    scaleVolume :: Rational -> Music (Pitch,Volume) -> Music (Pitch,Volume)
    such that scaleVolume s m scales the volume of each note in m by a factor of s.
    Hint:  To multiply a Rational r by an Integer i and yield an Integer result, do:
    round (r * fromIntegral i)
  3. Redefine revM from Section 5.6 using mFold.
  4. Using mFold, define a function insideOut that inverts the role of serial and parallel composition in a Music value. Using insideOut, see if you can:
    bulletfind a non-trivial value m :: Music Pitch such that m == insideOut m, and
    bulletfind a value m :: Music Pitch such that m :+: insideOut m :+: m sounds interesting. (You are free to define what "sounds interesting" means :-)
  5. Do something wild and crazy with Haskore.
  6. Extra credit:  Define a function minDur :: Music a -> Music a -> Dur such that minDur m1 m2 is the duration of the shortest of the two Music values m1 and m2.  The result should be well defined even for something like minDur (c 4 1) (repeatM (c 4 1)), in which one of the arguments is infinite in duration, although I do not expect your function to work on all possible infinite Music values.  In any case, try to make it work for as many anomalous cases as possible.

In addition, grad students taking CPSC 531 should:

  1. Prove that  mFold (:+:) (:=:) Primitive Modify == id
  2. Show that retro . retro and invert . invert are the identity on values created by line.