
On Fri, Jul 17, 2009 at 9:56 AM, Wolfgang
Jeltsch
Am Dienstag, 30. Juni 2009 00:01 schrieb David Menendez:
On Mon, Jun 29, 2009 at 4:31 PM, Ross Paterson
wrote: On Mon, Jun 29, 2009 at 02:37:56PM -0400, David Menendez wrote:
How about liftA2?
2 is a scary number. Do you have an example in mind where a customized liftA2 would be a big win?
I don't know about a big win, but my preference for Applicative has always been to define <*> and liftA2 as co-primitives, like so:
class Functor f => Applicative f where pure :: a -> f a liftA2 :: (a -> b -> c) -> f a -> f b -> f c (<*>) :: f (a -> b) -> f a -> f b
(<*>) = liftA2 ($) liftA2 f a b = fmap f a <*> b
Wouldn’t it make more sense to define (<*>) and pair as co-primitives, where pair = liftA2 (,)?
Defining pair in terms of liftA2 is simpler than defining liftA2 in
terms of pair.
pair = liftA2 (,) -- just partial application
liftA2 f a b =uncurry f <$> pair a b -- creates and destroys an
intermediate representation
--
Dave Menendez