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
Student
data type contains anInt
age and aString
name. Write a record syntaxdata
line.
-
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
Game
datatype withpos
field with type(Int,Int)
and apoints
of typeInt
.
-
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
-
Write a function to add 6 to the number of points.
score_6 :: Game -> Game
-
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.
-
Write an
updateScore
function that takes in aGame
and anAttackType
and 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