07. HC7 ‐ Haskell Chapter 7 Practical Tasks: Intro‐to‐Type‐Classes - wimsio/universities GitHub Wiki

HC7T1: Implement an Eq instance for a custom data type

Define a data type Color representing Red, Green, and Blue. Implement the Eq type class for it so that colors of the same type are considered equal.

HC7T2: Implement an Ord instance for a custom data type

Using the Color type from HC7T1, implement the Ord type class so that Red < Green < Blue.

HC7T3: Implement a function using multiple constraints

Write a function compareValues that takes two arguments of type a and returns the larger one. Ensure that a is both an instance of Eq and Ord.

HC7T4: Create a custom type and implement Show and Read

Define a data type Shape with constructors Circle Double and Rectangle Double Double. Implement Show and Read instances for it.

HC7T5: Implement a function that uses Num constraints

Write a function squareArea that calculates the area of a square given its side length. Ensure that the function works with any numeric type.

HC7T6: Use the Integral and Floating type classes

Define a function circleCircumference that takes a radius and returns the circumference. Ensure it works with both Integral and Floating numbers.

HC7T7: Implement a function using Bounded and Enum

Create a function nextColor that takes a Color and returns the next color in sequence. If it reaches the last color, it should wrap around.

HC7T8: Use Read to parse a value from a string

Write a function parseShape that takes a String and returns a Shape. The function should return Nothing for invalid inputs.

HC7T9: Define a type class with multiple instances

Create a type class Describable with a method describe. Implement it for Bool and Shape.

HC7T10: Use a function with multiple type class constraints

Write a function describeAndCompare that takes two Describable values and returns the description of the larger one.

Finished. Congratulations! Get your progress token here