2024 Review A
-
(
q1) You get a list ofMaybe IntGive out a list ofInt: all of the numbers that square to something be less than 100. Write a type signature and the function. -
(
q2) You get a list ofMaybe Int. Return their sum. Count -5 for eachNothing. -
Define a data using the field names in the definition the data should be called
Gameand contain aPointcalledpos, anIntcalledscore, and a list ofPointcalledenemies. -
(
ce: Game -> Int) Count how many enemies are in the game -
(
gold : Game -> Game) Increase the score by 20. Write your code in a way that will not change if you add more fields to theGame. -
(
ke: Game -> Point -> Game) remove any enemy within 10 of the given point. -
Can this be the signature of a fold helper function?
f :: Maybe Double -> Point -> Maybe DoubleExplain how you could use it, or explain why not.
-
(
sm: Game -> Game) update the game by sorting the list of enemies based on how close they are topos. -
What is the purpose of a
StdGen? Why doesrandomRoutput aStdGen? -
Modify (or pretend you modified) your
Gamerecord to contain aStdGencalledrng. Write a functionteleport :: Game -> Gamethat moves yourposto a random location with -9 <= x <= 9 and -5 <= y <= 5. -
The type
abeing in theEqtypeclass means there is a function:(=) : a -> a -> BoolMake your modified
Gametype an instance ofEqby checking everything except therngfor equality. -
Saying a type
bisBusymeans there is a functiongrind :: b -> Double -> band also a functionearn :: b -> Double -> Double. Write the class definition. -
Given
data SW = StudentWorker{studyHours :: Double, jobHours :: Double}Make
SWinto an instance ofBusyby havinggrindadd tostudyHours. Theearnfunction for SW multipliesjobHoursby the double given, which is interpreted as dollars per hour.