Search code examples
haskellhigher-order-functionsdefinitioncurrying

Are all curried functions considered higher-order functions?


If you take the definition from wikipedia of a higher-order function, it is a function which either takes another function as an argument and/or returns another function.

From my (limited) understanding, a curried function intermediately returns another function in order to accept another argument; opposed to accepting two (or more) arguments at the same time. So would this make all curried functions higher-order? More to the point, if they are considered higher-order, are they generally referred to as such?

This may be an obvious question but I am learning Haskell and can't seem to find an explicit answer.

Thanks!


Solution

  • As you say, If you take the definition from Wikipedia then yes: All curried functions are higher-order. Of course, that has the effect that most haskell functions are indeed higher-order (at least functions with two+ arguments defined idiomatially)

    Now, if you take any learning resource you'll find that curried functions aren't refered as higher-order. Instead a HOF is one that takes a function as argument. Strictly speaking curried functions have only one argument, therefore:

    not_higher_order :: a -> a -> a
    higher_order :: (a -> a) -> a
    

    Notice that the with the definition above the following function isn't a HOF because its argument is not a function.

    -- the argument isn't a function but it returns
    -- a a function which first argument is.
    not_higher_order? :: a -> (a -> a) -> a
    

    So most resources would say that a HOF is one that accepts another function in any of its arguments accepting that f :: a -> a -> a has two arguments instead of one.

    So in summary, within haskell's jargon and learning materials a HOFs are referred informally as those which any of its parameters is a function (where its parameters is not the best phrase, but everybody understand). This definition does not follow wikipedia's