Skip to content

18. HC18 ‐ Haskell Chapter 18 Practical Tasks: Functor

Bernard Sibanda edited this page Mar 17, 2025 · 1 revision
  1. HC18T1: Define a function mapToLower using fmap that converts all characters in a list to lowercase.
  2. HC18T2: Create a Functor instance for the binary tree type Tree.
  3. HC18T3: Define a function incrementTreeValues that adds one to every value in a tree using the Functor instance.
  4. HC18T4: Implement a function mapToBits to convert a list of Booleans to characters '1' or '0' using fmap.
  5. HC18T5: Define a Functor instance for the Either type, applying fmap only to the Right case.
  6. HC18T6: Implement a function applyToMaybe that uses fmap to transform the value inside a Maybe.
  7. HC18T7: Define a function fmapTuple that applies a function to the second element of a tuple (a, b) using the Functor instance of (,) a.
  8. HC18T8: Implement the identityLawCheck function to verify the Functor identity law.
  9. HC18T9: Implement the compositionLawCheck function to verify the Functor composition law.
  10. HC18T10: Create a function nestedFmap that applies a function to a nested structure using multiple fmap calls.

Chapter 11

  1. HC11T1: Implement a Functor instance for a three-element tuple ((,,) a b).
  2. HC11T2: Define a function fmapTriple that applies a function to the third element of a three-element tuple.

Chapter 12

  1. HC12T1: Write a function nestedMap that applies a function to a nested Functor of depth 2.
  2. HC12T2: Test the identity law on a nested Functor structure.

Chapter 13

  1. HC13T1: Create a Functor instance for the function type ((->) r).
  2. HC13T2: Implement a function that applies fmap to a function type and composes transformations.

Chapter 14

  1. HC14T1: Define a function replaceInFunctor using the <$ operator to replace all values in a Functor with a single constant.
  2. HC14T2: Implement and test the flipped version $> to achieve the same as <$.

Chapter 15

  1. HC15T1: Write a function applyVoid using void to trigger side effects within a Functor while discarding the result.
  2. HC15T2: Test void on different Functors like Maybe, [], and custom types.

Finished. Congratulations! Get your progress token here

Clone this wiki locally