[Swift-devel] Call function.

Mihael Hategan hategan at mcs.anl.gov
Fri Aug 12 10:15:19 CDT 2011


On Fri, 2011-08-12 at 19:04 +0530, Yadu Nand wrote:

> If all the functions existed in the same namespace (or if there is no
> concept of namespace),
> we don't need to pass functions to other functions, do we ? What I
> understand is that, we
> pass function-a to function-b so that function-a becomes available
> under function-b.
> 

No. You use first class functions of type T to be able to write a
generic function G that can use functions of type T without being tied
to a specific function of type T (say F) at the time you write G. In
other words, you can produce a G that works with a class of functions
(T) rather than a specific function.

In a sense you are correct. You don't really need it. You can always
copy-and-paste the body of G and manually replace calls to F. But that
seems to be a crappy way to do things.




More information about the Swift-devel mailing list