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
TrackEvent
which could be eitherSprint "100m"
orSprint "400m"
(or similar) orLongDistance 5
orLongDistance 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
similar
function which takes in two TrackEvents and givesTrue
if 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
Sunshine
orCloudy
. The temperature isHot
,Cold
, orFreezing
. Write a data typeWeather
that holds sky and temperature information. -
Write a function
goodNews
which is true when the weather is sunshine and cold or cloudy and hot. -
(
coldSky
). Given a list ofWeather
, find the sky state of the firstFreezing
day. Since there might not be a freezing day, this function should return aMaybe
.