Homework 9 — Programming Language Paradigms

Objectives

Working with the IO monad in Haskell.

Due Date

Beginning of class session 19.

Tasks

  1. Your programming for this assignment must be done in the folder HaskellWacky within your local copy of your SVN repository. Do an SVN update to get that folder; you’ll find a file WackyMaps.hs inside. Except where indicated, all your work for this assignment must be done in that file. This is so we can efficiently grade your and your classmates’ work.
  2. The file includes the line import Data.Map (Map, empty, insert, findWithDefault). This imports a library for manipulating finite maps (also known as dictionaries) in Haskell. Experiment with the following functions until you understand what they do:

    Can you predict the values of v1, v2, and v3 after loading the following code? (You don’t have to turn in any work for this task, but you should check your work using ghci.)

    m1 = empty
    m2 = insert 'x' 10 m1
    m3 = insert 'y' 20 m2
    v1 = findWithDefault 0 'x' m3
    v2 = findWithDefault 0 'y' m3
    v3 = findWithDefault 0 'z' m3
    m4 = insert 'y' 30 m3
    v4 = findWithDefault 0 'y' m4
    
  3. Implement a Wacky Prof. Quotes program as described in homework 3. Some suggestions:

Turn-in Instructions

Turn in your work by committing it to your SVN repository.