[Haskell-cafe] Applicative is like an Arrow
dave at zednenem.com
Sat Aug 17 19:37:42 CEST 2013
On Sat, Aug 17, 2013 at 8:23 AM, Mathijs Kwik <mathijs at bluescreen303.nl>wrote:
> damodar kulkarni <kdamodar2000 at gmail.com> writes:
> > Thanks for this nice analogy and explanation. This brings "monad
> > transformers" to my mind.
> > "without" monad transformers, the monads are bit crippled in their
> > applicability (please correct me if I am wrong)
> > and
> > "with" monad transformers the code becomes to some extent ugly (again,
> > please correct me if I am wrong)
> > I wonder, where and how the Monad transformers fit in here?
> Well, I'm glad you all liked my explanation =)
> Let me first correct 1 stupid mistake I wrote in the first paragraph:
> - Every idiom is an arrow and every arrow is a monad, but not the other
> way around.
> should obviously be:
> + Every Monad is an Arrow (with ArrowApply) and every Arrow is an Idiom,
> but not the other way around.
Every Idiom defines a static arrow:
newtype Static f a b = Static (f (a -> b))
instance Applicative f => Arrow (Static f)
Similarly, every arrow defines an idiom:
newtype WrappedArrow a b c = WrappedArrow (a b c)
instance Arrow a => Applicative (WrappedArrow a b)
The difference is that WrappedArrow (Static f) () is essentially the same
as f, but Static (WrappedArrow a ()) is not necessarily the same as a.
Basically, if an arrow can be made an instance of ArrowDelay, then it is no
more powerful than an Idiom (meaning anything you can write using the arrow
combinators can also be written with just the Applicative combinators):
class Arrow a => ArrowDelay a where
delay :: a b c -> a () (b -> c)
Dave Menendez <dave at zednenem.com>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe