### A should-read from Evan Laforge

"What Haskell Doesn't Have"...thank goodness.

- Get link
- Google+
- Other Apps

"What Haskell Doesn't Have"...thank goodness.

- Get link
- Google+
- Other Apps

After grinding through much of the "20 Intermediate Exercises" and just about all of the Monad Challenges, Monads make much more sense to me.

Therefore, I will follow the excellent advice of Stephen Diehl, and will not write a monad-analogy tutorial. Instead, I will say: do the 20 Intermediate Exercises, and take the Monad Challenges. To paraphrase Euclid, there is no royal road to Monads; the exercises and challenges take you down that road at whose end you'll see at least part of why Monads are so useful.

If you were trying to learn group theory and people were standing around you saying "groups are like the integers", "groups are like Rubik's Cube", "groups are like m x n matrices", "groups are like baryons and mesons", your situation would be much like the student of Haskell amidst all the monad analogy tutorials. In a sense they're backwards. All those things are groups, just as burritos et al. can at least be thought…

Therefore, I will follow the excellent advice of Stephen Diehl, and will not write a monad-analogy tutorial. Instead, I will say: do the 20 Intermediate Exercises, and take the Monad Challenges. To paraphrase Euclid, there is no royal road to Monads; the exercises and challenges take you down that road at whose end you'll see at least part of why Monads are so useful.

If you were trying to learn group theory and people were standing around you saying "groups are like the integers", "groups are like Rubik's Cube", "groups are like m x n matrices", "groups are like baryons and mesons", your situation would be much like the student of Haskell amidst all the monad analogy tutorials. In a sense they're backwards. All those things are groups, just as burritos et al. can at least be thought…

I assure you there will be no further allusions to Korean earworms. That said, on to the subject at hand...

Remember the exercise in the online Haskell course that had several tests to filter out weak passwords, all of which had to pass for the fictitious system to allow a**String** value to be used as a password? I wanted to make it easy to change, so I wanted to take a **[String -> Bool]** and get a **[Bool]** I could apply **and** to for the final thumbs up/thumbs down decision.

The first step: roll my own, which has a pleasing symmetry with**map** if you write it as a list comprehension:

**wonkyMap fs x = [f x | f <- fs]**

Then I stumbled across Derek Wyatt's blog post about using**sequence** for the purpose. Life was good... and then I got *Haskell Programming from first principles*, and life got better, because its authors do a very good job of explaining the **Applicative** type class. **Applicative** defines two functions, **pure** and **(<*>)**:

**class Functor f => Applicative f where**

** pure :: a -&g…
**

Remember the exercise in the online Haskell course that had several tests to filter out weak passwords, all of which had to pass for the fictitious system to allow a

The first step: roll my own, which has a pleasing symmetry with

Then I stumbled across Derek Wyatt's blog post about using

I came across the excellent Monad Challenges, a collection of exercises designed to take you through what have become some of the standard example monads and take you through the process that motivates monads as a way to handle these seemingly diverse data structures. Both the Monad Challenges and the 20 Intermediate Exercises are well worth your time. Doing them both is helping me a lot.

That said, they don't quite match up. 20IE's**banana** is **flip bind** and **apple** is **flip ap**. (This isn't unique; the also excellent *Learning Haskell from first principles* has as an exercise writing **bind** in terms of **fmap** and **join**, but the declaration it gives has the type of **flip bind**. The authors do point this out.) As a result, I find myself with something that there's got to be some way to simplify, of the form

**foo = flip $ (flip mumble) . (flip frotz)**

I'd like to think there's some sort of distributive-like law to be found and used here... watch this space.

That said, they don't quite match up. 20IE's

I'd like to think there's some sort of distributive-like law to be found and used here... watch this space.

## Comments