[Haskell-cafe] supplying some of the arguments to a function

Benjamin Franksen benjamin.franksen at bessy.de
Fri May 6 12:42:31 EDT 2005


On Friday 06 May 2005 17:32, Mark Goldman wrote:
> if I had a function f that took x y and z in that order, is there some
> way that I can supply y and z and get back a function that takes x?
> This question comes about after talking with a prof about currying and
> wether it buys you anything.

If you define

rotl3 f x y z = f y z x -- rotate left first 3 arguments

then, assuming f :: a -> b -> c -> d,

rotl3 f :: b -> c -> a -> d

and thus

rotl3 f your_y your_z :: a -> d

The already mentioned standard function 'flip' is equal to the left and right 
rotation for 2 arguments:

flip = rotl2 = rotr2 = \f x y -> f y x

You can imagine a family of 'rotl<n>' and 'rotr<n>' functions, indexed by the 
natural numbers. Unfortunately Haskell's type system(?) is not strong enough 
to declare the whole family at one stroke.

Would it be useful to have the first 3 to 5 instances in the standard library, 
i.e. rotl3, rotr3, rotl4, rotr4, rotl5, rotr5?

(You could also name them rotate_left3, ...)

HTH
Ben


More information about the Haskell-Cafe mailing list