proposal #3335: make some Applicative functions into methods,
and split off Data.Functor
dave at zednenem.com
Fri Jul 17 10:38:10 EDT 2009
On Fri, Jul 17, 2009 at 9:56 AM, Wolfgang
Jeltsch<g9ks157k at acme.softbase.org> wrote:
> Am Dienstag, 30. Juni 2009 00:01 schrieb David Menendez:
>> On Mon, Jun 29, 2009 at 4:31 PM, Ross Paterson<ross at soi.city.ac.uk> 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
Dave Menendez <dave at zednenem.com>
More information about the Libraries