Due: Tuesday January 17 at noon.
This assignment will familiarize you with GHC, Haskell, and Euterpea.
- Read the Preface and Chapters 1-3 of HSoM (The Haskell School of Music).
- Follow the instructions on the “Software Resources” link to install the Haskell Platform and Euterpea on your computer. (Alternatively, get a Zoo account so that you can use a Zoo machine.)
- Open a Command Prompt window and
Euterpea/example. Fire up GHCi (by typing
ghciat the command prompt) and start getting familiar with it. For example, try the following:
:las a shorthand for
:load, and you also can leave off the
.lhsextension on the file name.
Warning: If you get an error when loading this file, open a text editor on the file
exampledirectory), and change the line:
> times (n+1) m = m :+: (times n m)
> times n m = m :+: (times (n-1) m)
This is handy for reloading the last program, without having to type the name again. Note that
:ris shorthand for
These are all expressions whose evaluation results in MIDI output for the corresponding tune. If you don’t hear anything, something is probably wrong with your MIDI interface.
By typing just the name of the
Musicvalue, Haskell will print the value to the terminal
These return the types of each expression. As usual,
:tis a shorthand for
This displays information about things, in this case the definition of the
Musicdata type. Note that
:iis a suitable shorthand. This command also, handily, tells you where things are defined.
This will list all of the GHC commands at your disposal.
- Open a text editor on
Euterpea/example/HaskoreExamples.lhs. Note that all lines of code are preceded by a “
>” — this is because it is a “literate Haskell” file (thus the
.lhsextension). Any lines not starting with this prefix are considered as comments, and are ignored. Observe the other values that are defined in this module, and play with them using the above commands at the GHCi prompt.
- Finally, create your own Euterpea program as follows:
cdto a folder of your choice — it’s best not to stay in the
- Create a new file with a text editor, with the name is
- Start the file with the following header:
> module HW1 where
> import Euterpea
Remember that, because you are creating a
.lhs(literate Haskell) file, each of your lines of program code must begin with “
>“. You are required to write all of your homework assignments in this way.
- In the remainder of the file, create solutions to the programming exercises listed below. Once you are ready to try running something,
cdto the directory in which you created the file, start GHCi, and type:
Then, as you did above with
EuterpeaExamples.lhs, you can interact with the values in your program.
- Using the classes server, drop your solution (i.e. the file HW1.lhs) in …
- Prepare solutions to the following exercises from HSoM:
- From Chapter 1: Exercises 1.1, 1.2, 1.3, and 1.4.
- Also from Chapter 1, modify the definitions of
hListso that they each take an extra argument that specifies the interval of harmonization (rather than being fixed at -3). Rewrite the definition of
melto take these changes into account. Test your program to be sure it is working properly.
- From Chapter 2: Exercises 2.1, 2.2, 2.3.
- From Chapter 3: Exercises 3.1, 3.2, 3.3, 3.4, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12.
Some of these exercises are not programming exercises — no matter, you should still include the solutions in the
HW1.lhs file. You should make an attempt to write the programming solutions as elegantly and succinctly as possible. Remember to include a type signature for every top-level function or value that you define. Also be encouraged to write plenty of comments to document your code. In Haskell it is not uncommon to have more comments than code!