Mercurial > repo
view wisdom/monad-tutorials @ 1447:4ec67081254d
<GreyKnight> cat wisdom/monad_tutorials >> wisdom/monad-tutorials
author | HackBot |
---|---|
date | Sat, 12 Jan 2013 01:12:25 +0000 |
parents | 7b3d2f515be7 |
children | 680e91156ade |
line wrap: on
line source
Monads are a bucket brigade with project managers. Monads are like burritos. Think of a monad as a spacesuite full of nuclear waste in the ocean next to a container of apples. now, you can't put oranges in the space suite or the nucelar waste falls in the ocean, but the apples are carried around anyway, and you just take what you need. All space stations must put their astronauts into space suits before sending them out. Monads are just monoids in the category of endofunctors. Monads are like when you and a friend are trying to have a conversation about a mutual friend. Monads are like overloading the semicolon. class Monad m where ; (>>=) :: forall a b. m a -> (a -> m b) -> m b ; (>>) :: forall a b. m a -> m b -> m b ; return :: a -> m a ; fail :: String -> m a Actually, programming monads is much like cattle driving! Monads can be used like adapters (the adapter pattern) in OOP. A Monad is a class with a private field. A monad is just a label that you stick onto a value to tell the compiler it's not a pure functional value.