On types of functions

I propose to add a subsection “Type of Functions” to Manual / Types. This will be very helpful, especially for newcomers to learn the essentials of Julia types and functions. If anything wrong, please correct me.

Types of Functions

Each function has its own type, which is both concrete and singleton, and with Function as its supertype.

Recall that a function is consisted by one or more methods, therefore, a function could not have a similar type signature as in other programming languages, such as C, Haskell, etc.

2 Likes

You can actually have a function with no methods

julia> function foo end
foo (generic function with 0 methods)

but you can also specify signatures in Julia. A single syntax can create both a function and a method:

julia> (double(x::Integer)::Integer) = 2x
double (generic function with 1 method)

but that signature isn’t included in the type of the function, as you say. Though there have been discussions about whether it should. I personally would like to have a way of expressing the type of a function that takes Integer to Integer without specifying which particular function it is.

Thanks. A revised version:

Types of Functions

Each function has its own type, which is both concrete and singleton, and with Function as its supertype.

Recall that a function is consisted by methods, therefore, a function can not have a similar type signature as in other programming languages, while a method can.

Thanks for bringing up this issue, I made a PR for the docs:

(Incidentally, note that anonymous functions may not be singletons, I added an example).

1 Like