proposal #3335: make some Applicative functions into methods, and split off Data.Functor

Wolfgang Jeltsch g9ks157k at acme.softbase.org
Fri Jul 17 09:56:13 EDT 2009


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 (,)?

    class Functor f => Applicative f where

        pure :: a -> f a
        pair :: f a -> f b -> f (a,b)
        (<*>) :: f (a -> b) -> f a -> f b

        (<*>) = fmap (uncurry ($)) . pair
        pair fa fb = pure (,) <*> fa <*> fb

Best wishes,
Wolfgang


More information about the Libraries mailing list