3 ms·
Like Erik Meijer said in his course : there is nothing special or magic about monads. They don't deserve all the fuzz arround them. If you don't get why monads
by vans 11y ago
Like Erik Meijer said in his course : there is nothing special or magic about monads. They don't deserve all the fuzz arround them. If you don't get why monads are so awesome, maybe that's a proof that you understood them. Because there is nothing special !!
A monad is just a type with 2 functions defined. Like an interface with two methods in OO langages. The 2 functions have to respect some laws but you can imagine whatever implementation for the 2 functions as long as the laws are observed (et type signature of course).
You could invent a total different implementation for the list monad, for the maybe monad, etc (if you respect the laws). There is no hidden ultra powerfull meaning which implies only one implementation.
The best paper on monads i ever read is an ascii art one, by Graham Hutton :
http://www.cs.nott.ac.uk/~pszgmh/monads http://www.cs.nott.ac.uk/~pszgmh/monads
- kqr 11y ago> You could invent a total different implementation for the list monad, for the maybe monad, etc (if you respect the laws). Could you show such a different implementation for either list or maybe?
- jjaredsimpson 11y agonewtype HeadList a = HeadList { getHeadList :: [a] } instance Monad HeadList where return a = HeadList [a] m >>= f = HeadList $ fmap (head . getHeadList . f) (getHeadList m) This is a list instance that only keeps the head of function result, so it's basically just a map. But you could imagine putting any function that returns one result. min max avg normalize, etc
- ky3 11y ago-- const [] for a HeadList quux :: a -> HeadList a quux = HeadList . (const []) *Main> HeadList "hello... no wait" >>= quux HeadList {getHeadList = "*** Exception: Prelude.head: empty list Such breakage is verboten. This monad instance does not fly.
- paulddraper 11y agoIt's just the name. Whatever a monad is, it must be worth the name. (Yes, I know the history of the term.)