Skip to content

19. HC19 ‐ Haskell Chapter 19 Practical Tasks: Applicative

Bernard Sibanda edited this page Mar 17, 2025 · 1 revision
  1. HC19T1: Define an Applicative instance for a custom data type Pair a.
  2. HC19T2: Implement a function addThreeApplicative that adds three Maybe Int values using applicative style.
  3. HC19T3: Define a function safeProduct that calculates the product of a list of Maybe Int values, returning Nothing if any value is Nothing.
  4. HC19T4: Create a function liftAndMultiply that lifts a binary function (Int -> Int -> Int) using liftA2.
  5. HC19T5: Implement the function applyEffects using <*>, where it takes a tuple (IO Int, IO Int) and sums the values while printing them.
  6. HC19T6: Define the function repeatEffect that repeatedly executes an effect using forever.
  7. HC19T7: Write a function conditionalPrint using when that prints a message only when a given condition is true.
  8. HC19T8: Implement a custom function discardSecond that uses the <* operator to return the first argument after sequencing effects.
  9. HC19T9: Implement pureAndApply which demonstrates how pure works with applicative effects.
  10. HC19T10: Create a function combineResults that combines two Either values using applicative style.
  11. HC11T1: Define an Applicative instance for a custom data type Wrapper a.
  12. HC11T2: Implement a function sumThreeApplicative that adds three Either String Int values using applicative style.
  13. HC12T1: Implement the whenApplicative function that executes an action conditionally when a Bool is true.
  14. HC12T2: Define a function replicateEffect that replicates a given IO action a specified number of times using replicateM.
  15. HC13T1: Create a function sequenceEffects that combines a list of applicative effects into a single effect.
  16. HC14T1: Implement applyWithEffects to show how the <*> operator sequences two effects.
  17. HC15T1: Implement a function simulateMaybeEffect that applies a function to multiple Maybe values using applicative style.
  18. HC16T1: Define a function combineEitherResults that handles multiple Either computations with potential errors.
  19. HC17T1: Implement the function sequenceApplicative, combining a list of Maybe values and returning a Maybe [a].
  20. HC18T1: Implement a function replicateForever that applies an IO action infinitely using forever.

Finished. Congratulations! Get your progress token here

Clone this wiki locally