Argument order and partial function application

Hi all, Thanks for this great resource. I've got a basic question about partial function application: Let's say I have a very basic function: volumeFunction length width height = length * width * height Its type signature is: volumeFunction :: Int -> Int -> Int -> Int This implies that I first pass it the length, *then* the width, *then* the height. So while it is very easy for me to write volumeWithLengthTen = volumeFunction 10 , it's not possible to create a volumeWithWidthTen or volumeWithHeightTen. I can see how I might be able to "hack" my way into accessing the "width" argument with infix functions, but there's no way at all that I can see to access the height. This seems arbitrary to me: my volumeFunction doesn't need them in the order they're given. Is there a way around this? Could I somehow combine three smaller functions? I appreciate any insight. Tom

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 8/19/10 18:53 , Tom Murphy wrote:
I can see how I might be able to "hack" my way into accessing the "width" argument with infix functions, but there's no way at all that I can see to access the height. This seems arbitrary to me: my volumeFunction doesn't need them in the order they're given. Is there a way around this? Could I somehow combine three smaller functions?
volumeGivenLength, volumeGivenWeight, volumeGivenHeight: Int -> (Int -> Int
- -> Int)
- -- note that the above signature is the same as Int -> Int -> Int -> Int
volumeGivenLength = volumeFunction -- function taking w, h
volumeGivenWidth = flip volumeFunction -- function taking l, h
volumeGivenHeight = flip (flip . volumeFunction) -- function taking l, w
You can in general achieve any desired permutation of parameters, at the
expense of your sanity:

I'm guessing that this isn't the actual function, as your volume function is already agnostic regarding argument order. Making
volumeWithWidthTen = volumeFunction 10
If the argument order does matter you can get around some order restrictions using functions like flip, but it's often clearer to be explicit:
volumeWithWidthTen length = volumeFunction length 10
Is that what you were looking for?
On Fri, Aug 20, 2010 at 6:53 AM, Tom Murphy
Hi all, Thanks for this great resource. I've got a basic question about partial function application:
Let's say I have a very basic function: volumeFunction length width height = length * width * height Its type signature is: volumeFunction :: Int -> Int -> Int -> Int
This implies that I first pass it the length, *then* the width, *then* the height. So while it is very easy for me to write volumeWithLengthTen = volumeFunction 10 , it's not possible to create a volumeWithWidthTen or volumeWithHeightTen. I can see how I might be able to "hack" my way into accessing the "width" argument with infix functions, but there's no way at all that I can see to access the height. This seems arbitrary to me: my volumeFunction doesn't need them in the order they're given. Is there a way around this? Could I somehow combine three smaller functions?
I appreciate any insight. Tom _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

If the argument order does matter you can get around some order restrictions using functions like flip, but it's often clearer to be explicit:
volumeWithWidthTen length = volumeFunction length 10
Is that what you were looking for?
It's exactly what I'm looking for; thank you. A nice flash of insight once in a while keeps the brain sharp. Thanks too, Brandon, for the education about flips. Tom
participants (3)
-
Brandon S Allbery KF8NH
-
Lyndon Maydwell
-
Tom Murphy