Add <**>
safareli opened this issue · comments
reopening #32
the operator is useful when using some Applicative where ordering metters. for example it's used extensively in optparse-applicative
like this parser <**> helper
it would be useful for other libs providing applicative interface
here is implementation similar to what's in haskell, (note that it's not just flip apply
):
infixl 4 applyFlipped as <**>
applyFlipped :: forall f b a. Apply f => f a -> f (a -> b) -> f b
applyFlipped = lift2 (#)
Are you aware of any other libraries where it makes sense to use <**>
? I can't think of any.
Any parsec like lib can use it, or just any structure where effects are sequenced in ltr or rtl direction. note f_a # apply f_a2a
will not work as it will result in effects of f_a2a to be performed first when f_a <**> f_a2a
will sequence effects as they appear in code.
Yeah: I'm aware of the reason to have this function, I'm just not convinced that it's useful enough to deserve a spot in Prelude. I've used plenty of applicative structures with non-commutative effects, but I don't ever remember wanting this. I'd probably prefer to use
ado x <- f_a
f <- f_a2a
in f x
The fact that Haskell has this function is a point in favour of adding it, but personally, it's not quite enough to sway me.