| |
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.
- Define a function repM :: Int -> Music a -> Music
a such that repM n m repeats
m n times.
- 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)
- Redefine revM from Section 5.6 using
mFold.
- 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:
 | find a non-trivial value m :: Music Pitch
such that m == insideOut m, and |
 | find a value m :: Music Pitch such that
m :+: insideOut m :+: m sounds interesting.
(You are free to define what "sounds interesting" means :-) |
Do something wild and crazy with Haskore.
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:
- Prove that mFold (:+:) (:=:) Primitive
Modify == id
- Show that retro . retro and
invert . invert are the identity on values
created by line.
|