17. HC17 ‐ Haskell Chapter 17 Practical Tasks: Semigroup‐and‐Monoid - wimsio/universities GitHub Wiki
-
HC17T1: Create a
Severity
data type representing the severity of an emergency with four levels (Low
,Medium
,High
,Critical
). Implement aSemigroup
instance for this type, where the higher severity overrides the lower one. -
HC17T2: Define a
Min
andMax
newtype for anyOrd
type and implement their respectiveSemigroup
instances usingmin
andmax
. -
HC17T3: Implement the
Monoid
instance for theSeverity
type, where the identity value isLow
. -
HC17T4: Implement the
Monoid
instance for theSum
newtype, where the identity element is0
. -
HC17T5: Implement a function
combineLists
that uses theSemigroup
instance to concatenate two lists of integers. -
HC17T6: Define a function
maxSeverity
that combines a list ofSeverity
values usingmconcat
. -
HC17T7: Implement a function
multiplyProducts
that takes a list ofProduct
values and returns the combined result usingmconcat
. -
HC17T8: Write a function
foldWithSemigroup
that accepts any list of a type with aSemigroup
instance and combines all elements usingfoldr
. -
HC17T9: Define a
Config
data type with fields forloggingLevel
,timeout
, andretries
. Implement aSemigroup
instance that combines configurations by taking the maximumloggingLevel
andretries
and the minimumtimeout
. -
HC17T10: Implement the
Monoid
instance for theConfig
data type, where the identity element is a configuration with the lowestloggingLevel
, highesttimeout
, and lowestretries
. -
here
Finished. Congratulations! Get your progress token