17. HC17 ‐ Haskell Chapter 17 Practical Tasks: Semigroup‐and‐Monoid - wimsio/universities GitHub Wiki

  1. HC17T1: Create a Severity data type representing the severity of an emergency with four levels (Low, Medium, High, Critical). Implement a Semigroup instance for this type, where the higher severity overrides the lower one.

  2. HC17T2: Define a Min and Max newtype for any Ord type and implement their respective Semigroup instances using min and max.

  3. HC17T3: Implement the Monoid instance for the Severity type, where the identity value is Low.

  4. HC17T4: Implement the Monoid instance for the Sum newtype, where the identity element is 0.

  5. HC17T5: Implement a function combineLists that uses the Semigroup instance to concatenate two lists of integers.

  6. HC17T6: Define a function maxSeverity that combines a list of Severity values using mconcat.

  7. HC17T7: Implement a function multiplyProducts that takes a list of Product values and returns the combined result using mconcat.

  8. HC17T8: Write a function foldWithSemigroup that accepts any list of a type with a Semigroup instance and combines all elements using foldr.

  9. HC17T9: Define a Config data type with fields for loggingLevel, timeout, and retries. Implement a Semigroup instance that combines configurations by taking the maximum loggingLevel and retries and the minimum timeout.

  10. HC17T10: Implement the Monoid instance for the Config data type, where the identity element is a configuration with the lowest loggingLevel, highest timeout, and lowest retries.

  11. Finished. Congratulations! Get your progress token here