Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why higher order procedures?

So if a language provides higher order procedure then I can have procedure that returns procedure. Something like:

(define (Proc a b c)
  (lambda (x) ( #| method body here in terms of a b c and x |# )))

To create new procedure, I would just do something like:

(define ProcA (Proc a1 b1 c1)) ; Would create ProcA that has 1 argument

Similar task could be done in a language which does not support higher order procedure by defining Proc that takes 4 instead of 3 arguments and calling this procedure to define ProcA, like:

(define (Proc a b c x) ( #| method body -- does not return any procedure |# )
(define (ProcA x) (Proc a1 b1 c1 x))

So why is there so much fuzz about higher order procedure? Am I missing something?

like image 509
StackUnderflow Avatar asked May 07 '09 02:05

StackUnderflow


People also ask

What are the benefits of using higher order functions?

Higher order functions can help solve many problems. With that said, with the many useful benefits that higher order functions can bring to the table like code size reduction and re-usability, you will decrease the likelihood of stressing over people around you when used that way.

What are the goals of order processing?

Although any company’s order processing procedures are unique to its business and customer needs, maximizing accuracy, cost efficiency and productivity remains a common goal for all businesses. Here are some tips to improve order processing and realize these goals:

How can you improve order processing?

Here are some tips to improve order processing and realize these goals: 1. Workflow efficiency: Businesses work better when all the moving parts are in sync. Make sure to continuously track workflows to determine where they can be refined. Wherever possible, simplify communication to speed up decision-making — without sacrificing accuracy. 2.

What happens while an order is processing?

Order processing includes five main steps from order placement to delivery — and sometimes continues on if a customer starts a return process. But what is actually happening while an order is processing? Here’s a breakdown of the typical workflow:


2 Answers

It's a good observation that a function that returns another function is the same as a function that takes two arguments. This is called "Currying". Put another way, a function from A to B is proof of a logical implication, that A implies B, or:

A => B.

As you note, if A implies that B implies C, then A and B implies C, or:

(A => (B => C)) <==> ((A, B) => C)

But a higher order function is not necessarily a function that returns another function. A higher-order function is a function that takes another function as its argument. This is an important difference, and HOFs are immensely powerful programming tools.

For example, consider this Haskell function:

map :: (a -> b) -> [a] -> [b]
map f [] = []
map f (x:xs) = f x : (map f xs)

This higher-order function takes a function f and applies it to every element in a list. In languages without HOFs, you would do what this function does with a loop or something similar, but in a language that has HOFs, you can call f for every element in the list with a simple call like this:

map f myList

Sure, control constructs in languages let you approximate higher-order functions, but a language that has higher-order functions lets you invent your own control constructs. Scheme certainly qualifies.

like image 121
Apocalisp Avatar answered Oct 11 '22 01:10

Apocalisp


I won't try to recapitulate the argument here, but in Why Functional Programming Matters, John Hughes argues that higher-order functions are useful because they provide more effective ways to "glue together" parts of a program, and thereby they make it easier to reuse code. The examples are in a very old language that is no longer used much, but they are still easy to follow and pretty convincing. Reading John's paper is a good way to get a detailed answer to your question "why is there so much fuzz about higher-order procedures".

like image 26
Norman Ramsey Avatar answered Oct 11 '22 02:10

Norman Ramsey