partial application

Koen Claessen
Mon, 18 Mar 2002 15:59:54 +0100 (MET)

Cagdas Ozgenc wondered:

 | Is there a reason why partial application cannot be
 | applied in arbitrary order? Was it a technical
 | difficulty in the design of Haskell? Or is it just
 | following beta reduction rigorously?

Alastair David Reid answered:

 | Haskell doesn't dictate any particular evaluation
 | order.  If you look at the name of the Haskell report,
 | it calls Haskell a "non-strict" language not a "lazy"
 | language.

Somehow I do not think that Cagdas was talking about
evaluation order at all. I think he referred to the
following: Suppose I have a function f which is defined to
have 3 arguments:

  f x y z = ...

Now, when I want to partially apply f to two arguments, say
1 and 2, I can say this:

  ... (f 1 2) ...

However, if I want to leave out the middle argument, I have
to say:

  ... (\y -> f 1 y 3) ...

And, similarly, for the first one:

  ... (\x -> f x 2 3) ...

This seems rather ugly, since the order of arguments in a
function plays a crucial role. For example, the map function
takes the list as its second argument, since it is so much
more common to partially apply map with the function rather
than the list.

For 2-argument functions, the sections notation might help:

  (1 `f`)         -- === (f 1) === (\y -> f 1 y)
  (`f` 2)         -- === (\x -> f x 2)

In a distant past, Erik Meijer and I experimented with
introducing the syntax:

  (f 1 2 _)
  (f 1 _ 3)
  (f _ 2 3)

But it became all very clumsy.


Koen Claessen
Chalmers University, Gothenburg, Sweden.