SI 413 Fall 2021 / Project


This is the archived website of SI 413 from the Fall 2021 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

Haskell

The Haskell programming language was designed by committee in 1990. Haskell has similar features to Scheme, only more extreme. It is a pure functional language, so there are never any side effects. It features lazy evaluation, which basically means that every function is a special form. And it has types too - of course you can also use types as arguments and create them on the fly, etc. It's a programming language for programming language lovers.

Useful Links

  • Learn You a Haskell for Great Good! is a fun and well-written (free online) book about the language.
  • The Learning Haskell has a number of other references.
  • Wikipedia page
  • 99 bottles of beer program, courtesy Dr. Roche:
    import qualified Data.Char as Char
    
    cap :: String -> String
    cap ""     = ""
    cap (x:xs) = Char.toUpper x : xs
    
    onwall :: (Integral a, Show a) => a -> String
    onwall = (++ " on the wall") . bottles
    
    bottles :: (Integral a, Show a) => a -> String
    bottles n = howmany n ++ " bottle" ++ plural n ++ " of beer"
      where howmany 0 = "no more"
            howmany n = show n
            plural 1 = ""
            plural _ = "s"
    
    drink :: Integral a => a -> String
    drink 0 = "Go to the store and buy some more, "
    drink _ = "Take one down and pass it around, "
    
    consume :: Integral a => a -> a
    consume 0 = 99
    consume n = pred n
    
    verse :: (Integral a, Show a) => a -> [String]
    verse n = map (foldl1 (++)) [[cap (onwall n), ", ", bottles n, "."],
                                 [drink n, onwall (consume n), "."]]
    
    main :: IO ()
    main = mapM_ putStrLn $ foldl1 ((++) . (++ [""])) $ map verse [99,98..0]

Tools

We will use GHC, the Glasgow Haskell Compiler, version 8.0.2.

Everything you need is already installed on CS department lab machines.

To install on your virtual machine, follow these steps:

  1. Run sudo apt install haskell-platform haskell-platform-doc
  2. That's it!

How I will run your code

The programs you submit should be in a single file called proj.hs, for either part of the project. Be sure to include a main function.

When developing and testing your code, I strongly recommend using the interactive REPL provided by the ghci program. This is the easiest way to load up your code in the proj.hs file and test it on different inputs.

For submission, you should actually compile and run your program from the command line using ghc. I will test your code by running the following commands using the software available in the lab environment or using the instructions above:

ghc proj.hs
./proj

Phase 1 Requirements

For this language, you need to implement modifications B, C, D, and G. See the Phase 1 page for details on what this means.

Phase 2

See the Phase 2 Page for the list of suggested problems. Of the ones listed, I recommend the following as being most well-suited for Haskell:

  1. Matrix Calculator
  2. Game Scheduler
  3. Frequency count
  4. Guess the language
  5. Find the missing digits
  6. Rock, Paper, Scissors
  7. ??? (you choose!)