The Monad Challenges

PureScript Edition

A set of challenges for jump starting your understanding of monads.

Outline

Set 1: Random Numbers

Set 2: Failing Computations

Set 3: Combinations

Set 4: Common Abstraction

Set 5: Do Notation

MCPrelude documentation

This project is maintained by shaunplee and is a fork of the Monad Challenges maintained by mightybyte

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Combinations of three things

Our allCombs function is more general but it still only lets us generate combinations of two things. Now implement an allCombs3 function that generates combinations of 3 things. Don’t try to do anything fancy yet. Just use the most straightforward approach you can think of.

allCombs3 :: forall a b c d. (a -> b -> c -> d) -> Array a -> Array b -> Array c -> Array d

For convenience, MCPrelude defines a data Triple with Show instance, e.g.:

> Triple 42 "hello" 3.141
(42,"hello",3.141)

Here is example output to check your allCombs3 function.

allCombs3 Triple [1,2] [3,4] [5,6] == [(1,3,5),(1,3,6),(1,4,5),(1,4,6),(2,3,5),(2,3,6),(2,4,5),(2,4,6)]

Previous Page - Next Page