[Haskell-beginners] Argument order and partial function application

Brandon S Allbery KF8NH allbery at ece.cmu.edu
Thu Aug 19 19:13:56 EDT 2010

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:

    <allbery_b> @pl \h -> \a b c d e f g -> foo a b c d e f g h
    <lambdabot> flip (flip . ((flip . ((flip . ((flip . ((flip . (flip .))
.)) .)) .)) .) . foo

- -- 
brandon s. allbery     [linux,solaris,freebsd,perl]      allbery at kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university      KF8NH
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/


More information about the Beginners mailing list