8. Sum Types I
A sum type represents a choice: one of several possibilities. Choose
Good or Evil. A Grade could be A, B, C, D, or F.
A Maybe Int is one of these types; it could be Just 10 or Nothing.
-
Define a
TrackEventwhich could be eitherSprint "100m"orSprint "400m"(or similar) orLongDistance 5orLongDistance 26(or similar). The idea is that the LongDistance is measured in miles, but there are no actual units included in that data. -
Write a
similarfunction which takes in two TrackEvents and givesTrueif both are Sprints or both are LongDistance with the distance less than 10 (“short long distance”), or both are LongDistance with the distance greater than or equal to ten (“very long distance”). -
The sky is
SunshineorCloudy. The temperature isHot,Cold, orFreezing. Write a data typeWeatherthat holds sky and temperature information. -
Write a function
goodNewswhich is true when the weather is sunshine and cold or cloudy and hot. -
(
coldSky). Given a list ofWeather, find the sky state of the firstFreezingday. Since there might not be a freezing day, this function should return aMaybe.