[Haskell-beginners] partial application

Keshav Kini keshav.kini at gmail.com
Mon Dec 3 22:04:36 CET 2012


Brent Yorgey <byorgey at seas.upenn.edu> writes:
> On Mon, Dec 03, 2012 at 12:28:08PM +0000, Miguel Negrao wrote:
>> Is there a syntax in Haskell for partial application that would be something like this the following ?
>> 
>> f a b c d  = a +b+ c+ d
>> 
>> g = f _ 1 2 3 
>> 
>> or the only way to do it is like below ?
>> 
>> g = (\x -> f x 1 2 3) 
>
> Yes, a lambda is the only way to do it.

In the case where you have fewer (specifically two) variables, you can
also use `flip`::

   f a b = a / b

   -- g = f _ 2 can be written as:
   g = flip f 2

-Keshav




More information about the Beginners mailing list