Haskell confusion (81)

76 Name: #!/usr/bin/anonymous : 2006-04-08 01:20 ID:Heaven

>>75

(`func`b)

will do that, or (flip func) b. (That is still not a real-world example -- you haven't explained why you'll want to do func a too, and if you don't then you can just reverse the first two arguments.)

reverse ls = foldl (flip (:)) [] ls

The above defines reverse to be a function taking an argument ls, returning foldl (flip (:)) [] ls. In the following definition:

reverse = foldl (flip (:)) []

you've done the same thing, but without explicitly naming and passing off an argument. Cleaner and more high-level, and especially useful when you're defining a function as the composition of other functions. Section 8.3 of "A Gentle Introduction to Haskell" has a good example of this: http://haskell.org/tutorial/stdclasses.html

This thread has been closed. You cannot post in this thread any longer.