[Haskell-beginners] Simpler than lifting

Brent Yorgey byorgey at seas.upenn.edu
Mon Mar 18 15:17:44 CET 2013


On Mon, Mar 18, 2013 at 10:15:53AM -0400, Brandon Allbery wrote:
> On Mon, Mar 18, 2013 at 9:59 AM, Adrian May
> <adrian.alexander.may at gmail.com>wrote:
> 
> > infixl 6 ~+, ~-
> > f ~+ g = \p -> f p + g p
> > f ~- g = \p -> f p - g p
> >
> > but I feel that the prelude must have already taken care of such things.
> > What's the proper way to do it?
> >
> 
> Not in the Prelude (which is specified by the Haskell Language Report and
> difficult to change), but I think you want to look at
> Control.Applicative.

In particular, (~+) = liftA2 (+), and similarly for (~-).  This uses
the  ((->) e)  instance of Applicative.

-Brent



More information about the Beginners mailing list