8. Walk II

Exercises introducing record syntax.

In this assignment you should practice writing all of your functions two ways: using pattern matching and using the record updating syntax with {...}.

  1. The Student data type contains an Int age and a String name. Write a record syntax data line.
  1. Write two versions of a function to make the student one year older. One using pattern matching, the other using record updating.

     older :: Student -> Student
    
  1. Make a Game datatype with pos field with type (Int,Int) and a points of type Int.
  1. Write a move_right fucntion to change the x coordinate of the pos in the Game to be x plus a given number. Write a second version so you have both pattern matching and record updating versions.

     move_right :: Game -> Int -> Game
    
  1. Write a function to add 6 to the number of points.

     score_6 :: Game -> Game
    
  2. Define a data type AttackType to store this information: an attack can be one of the following:

    • Nothingg
    • Whack
    • Smash
    • Fire Int

    The (Fire 15) attack means a fire attack that will give you 15 points.

  1. Write an updateScore function that takes in a Game and an AttackType and puts out a game with more points. The number of points to add depends on the AttackType.

    AttackType Points
    Nothingg 0
    Whack 2
    Smash 5
    Fire n n
     updateScore :: Game -> AttackType -> Game