CS 119 Lab 1 – Simple Haskell Expressions

Objectives

  • Write simple expressions in Haskell
  • Model the calculation of expressions
  • Perform the following tasks in the order given.

    1. For your very first session you will have to do a one-time setup of then Eclipse Haskell plug-in. Click the Configurator wizard button (fp) on the toolbar.  Enter (or use the Browse option) C:\ghc\ghc-6.8.2\bin\ghc.exe as the path to the GHC executable.  Click Next twice (ignoring Haddock).  Enter C:\Program Files\WinHugs\hugs.exe as the the path to the HUGS executable.  Click Finish.
       
    2. Download the Lab1 project and import it into Eclipse as a Haskell project (select Haskell as the Perspective under the Window directory).
       
    3. To compile the Example1 code, open it in the editor, select Run As... and then select Hugs 98 session. 
       
    4. In the console window you will see the prompt at which you can type Haskell expressions.  Try some of the examples given in the notes.  Test out the addS and thirdPerson functions to verify that they work as expected. Make sure that you understand how all the functions in the Words module behave.
       
    5. To compile the Quilt code, open it in the editor, and select Run As.  and then select GHCi session.  You will get some error messages.  Don't panic!  From the Run menu, select Open Run Dialog...  In the arguments box you will see something like
       
          --interactive "G:\lab1\src\Quilt.hs"

      Of course your path to Quilt.hs may be different.  Change this to look like

          --interactive "G:\lab1\src\Quilt.hs" -i.:"G:\lab1\src"

      Now when you run this code it should compile and load correctly.  Try out the quilt examples from the notes.  Make sure that you understand how these functions from the Quilt module behave.
       

    6.  
      Assignment:
      Use the Words module to write a function:

      insertAnd :: Language -> Language
      insertAnd s = ...

      which inserts the word "and" as the next to last word of the sentence.
      For example,

      insertAnd (sent "John Bill Wayne Fred")  => [John Bill Wayne and Fred]


       

    7. Try out the function plural given in the example functions on the words "fly" and "cat".

       
      Assignment:
      Modify the function plural so that it works correctly for words ending in a vowel followed by the letter "y" – e.g. "toy". Also modify the function so that it works for words ending in "x" like "box".


       

    8. We will build some additional tools for manipulating quilts

       
      Assignment:
      Define functions halfTurn and quarterTurnLeft which will rotate a quilt appropriately.


       


    9.  
      Assignment:
      Define a function sideBySide  which will combine two quilts next to each other, with the first quilt on the left and the second quilt on the right.  Make sure the the two quilts stay in their original orientation.


       


    10.  
      Assignment:
      Define a function pinwheel where

      draw (pinwheel testBB) will look like :

                

      Test out pinwheel on some other quilts.


       

    11. If you look at the bottom of the Quilt module you will see the definitions of the basic blocks.  They are formed by defining polygons to be drawn.  Create some basic blocks of your own and test them out.
       
    12. Email your modified zipped project to me for grading.