John Meacham writes:
On Tue, Oct 17, 2006 at 11:09:00AM +0100, Ross Paterson wrote:
in which the left-associative <*> buries the function in the parser, while you'd prefer
fmap (\ ((x,y),z) -> f x y z) (p <> q <> r)
(where p <> q is equivalent to pure (,) <*> p <*> r) so presumably you'd want <> as a method in Applicative too.
I think the main ones would be (for frisby's use):
<* *> <> optional
Would it help at all if liftA2 were part of the Applicative class? I've usually defined Applicative like so, class Functor f => Applicative f where pure :: a -> f a (<*>) :: f (a -> b) -> f a -> f b liftA2 :: (a -> b -> c) -> f a -> f b -> f c (<*>) = liftA2 ($) liftA2 f a b = fmap f a <*> b (The pre 6.6 arrows package defined Control.Sequence in this fashion.) Using that, you could define instance Applicative P where pure = P . Unit liftA2 f (P a) (P b) = P $ PMap (uncurry f) (Then a b) in which case <* and *> end up the same as <<- and ->>. -- David Menendez <zednenem@psualum.com> | "In this house, we obey the laws <http://www.eyrie.org/~zednenem> | of thermodynamics!"