
15 Sep
2012
15 Sep
'12
10:20 a.m.
Joel Burget, Fri 2012-09-14 @ 19:08:29-0700:
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
Nitpick: You are using the Functor instances of Maybe and Either here, not Applicative. (<$>) == fmap; it just happens to be defined in the Control.Applicative module.