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.

Using the abstraction

Now your Set4.purs module has fairly decent set of abstract tools all built on the Monad interface. Now go back through sets 1, 2, and 3 and redo them all using the library of functions you built up in Set4.purs. Since Gen is now a newtype you will have to make some changes to the functions that use it. This may seem like a waste of time, but it will develop your familiarity with the names actually used* by PureScript’s monad library. This is the core of developing a working knowledge of monads. The first three sets were the motivation. Now we’re getting to the real world use.

* This is a lie. Unlike Haskell, sequence is part of Data.Traversable, and PureScript’s monad libraries don’t have liftM2 and liftM3. Instead, you could use lift2 and lift3 from Apply (in Control.Apply), which is a superclass of Monad, or you might rewrite using <$> and <*>. Also, pure is actually a member of Applicative, but these Monad Challenges were originally written for Haskell and asked the reader to implement return and bind for their Monad instances. In Haskell, for path-dependent reasons, return is a member of Monad and is equivalent to pure, as of the adoption of the Haskell 2014 Applicative => Monad proposal, when Applicative became a superclass of Monad in Haskell as well (implemented in GHC 7.10). In current versions of Haskell, pure from Applicative provides the default implementation of return in Monad instances.

Previous Page - Next Page