What is the best way to call a function of two variables on more than two variables?
Well let's see here. In Racket, I would say use a macro.
#lang racket
(define-syntax apply*
(syntax-rules ()
[(apply* f x y)
(f x y)]
[(apply* f x y rest ...)
(apply* f (f x y) rest ...)]))
(define (plus a b) (+ a b))
(apply* plus 1 2 3 4 5) ;; => 15
Here we have deemed that the apply* form takes a function of two arguments, and calls it on an arbitrarily long list of arguments. This will literally expand (apply* max x y z) into (max (max x y) z), allowing you to write the pretty code and letting the macro expander turn it into the verbose code.
However, Haskell macros are annoying to deal with, and rather unidiomatic. So let's use a function instead. What will this function look like?
applyStar :: (a -> a -> a) -> [a] -> a
The first argument is a 2-arg function, which takes two things of the same type, and spits out a thing of that type. This we can see from the desired result: max (max x y) z, the output must be the same type as the inputs. Haskell doesn't let you define functions of variable arity, so in order to simulate that, we write a function that takes a list of arguments, [a].
Stop. Hoogle time! If you search for the type signature (a -> a -> a) -> [a] -> a at http://haskell.org/hoogle , then you'll find that this is called foldl1 and is already implemented for you.
maximumfunction in the Prelude. Here is how it is implemented (and note that it is specialised forInts andIntegers).[x]is not an array, it is a list, particularly, an immutable singly-linked list. You can find implementations of arrays atData.ArrayandData.Vector.