3 ms·
Monads are a special case of Arrows. You can think of Arrows as generalised functions: the type of a function is X -> Y, whilst the type of an arrow is A X Y,
by dododo 16y ago
Monads are a special case of Arrows.
You can think of Arrows as generalised functions: the type of a function is X -> Y, whilst the type of an arrow is A X Y, where A takes the place of the infix type ->. So another way you can write the type of a function is (->) X Y, from this (+ technicalities) we see that functions are Arrows.
Monads are a special case of arrows where A X Y becomes X -> M Y or (without the infix syntactic sugar) (->) X (M Y); Monads can take control of the outputs from operations, whilst Arrows can take control of both the input and output to operations.
I found Monads made a lot more sense after I learnt about Arrows because Arrows are what I wanted Monads to be.
btw, the "killer app" for monads, imho, is parsec:
http://legacy.cs.uu.nl/daan/parsec.html http://legacy.cs.uu.nl/daan/parsec.html
whilst the "killer app" for arrows is probably FRP:
http://www.haskell.org/haskellwiki/Functional_Reactive_Programming http://www.haskell.org/haskellwiki/Functional_Reactive_Progr...
- eru 16y agoYes. And Monads are also a special case of Functors (and of Pointed Functors). Interestingly, Functors and Arrows are different generalizations of Monads, and neither is a generalization of the other. I also agree with Parsec being the killer application of Monads. In a purely functional setting Input/Output and similar things suffice as a motivation for monads, but that won't excite any Java programmer. But using Monads for a parser, like Parsec does, would also be a good idea in Java.
- intoverfl0w 16y agoCouldn't agree more on all points, particularly the last two.