8. Walk II
In this assignment you should practice writing all of your functions
two ways: using pattern matching and using the record updating syntax
with {...}.
- The
Studentdata type contains anIntage and aStringname. Write a record syntaxdataline.
-
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
- Make a
Gamedatatype withposfield with type(Int,Int)and apointsof typeInt.
-
Write a
move_rightfucntion 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
-
Write a function to add 6 to the number of points.
score_6 :: Game -> Game -
Define a data type
AttackTypeto store this information: an attack can be one of the following:NothinggWhackSmashFire Int
The
(Fire 15)attack means a fire attack that will give you 15 points.
-
Write an
updateScorefunction that takes in aGameand anAttackTypeand puts out a game with more points. The number of points to add depends on theAttackType.AttackType Points Nothingg 0 Whack 2 Smash 5 Fire n n updateScore :: Game -> AttackType -> Game