I find the Monad instance for Maybe and Either very useful. You can do things like the following (which technically only uses the Applicative instance):
Prelude Control.Applicative> (*3) <$> (+2) <$> Just 1 Just 9 Prelude Control.Applicative> (*3) <$> (+2) <$> Nothing Nothing Prelude Control.Applicative> (*3) <$> (+2) <$> Left "error" :: Either String Int Left "error" Prelude Control.Applicative> (*3) <$> (+2) <$> Right 1 :: Either String Int Right 9 Also, Maybe and Either are not "implemented as monads". They are defined using `data` like you suggest: data Maybe a = Nothing | Just a data Either a b = Left a | Right b You can even look up their definitions using ghci using `:i Either` or `:i Maybe`. Monad comes in because they're both instances of the Monad type class. Take a look at the list monad for another one that doesn't modify state or communicate with an outside interface. - Joel On Friday, September 14, 2012 at 6:08 PM, Andrew Pennebaker wrote: > > Everyone in the Haskell cafe probably has a secret dream to give the > > best "five minute monad talk." Challenge: get someone to have a > > competition at one of the conferences where students all give their > > best "five minute monad talk" and try to find the most comprehensible > > one! > > Haha, maybe that's why I'm writing. > > Agree on all points, not just this quotation. > > Yeah, IO and Maybe are the first monads most new Haskell programmers > encounter. Perhaps a tour of RVars or the accelerate library would give a > better impression. I bet a lot of students get the concept of pure functional > programming, and if you shock them with: "So how would you implement a > PRNG?", they would understand the role monads play. > > Given that Maybe and Either don't modify state, nor do they communicate with > outside interfaces, nor do they specify computation ordering, I don't > understand why they're implemented as monads. Why not a primitive typeclass > or even datatype declaration? > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org (mailto:Haskell-Cafe@haskell.org) > http://www.haskell.org/mailman/listinfo/haskell-cafe > >
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe