typeof(myFunction) does not work for a self-defined function myFunction

julia> function myFunction()
println(“haha, you die”)
end
myFunction (generic function with 1 method)

julia> println(“type of myFunction:”, typeof(myFunction))
type of myFunction:typeof(myFunction)

a bit strange, right?

What do you mean “does not work”?

The type of a function is written like that:

julia> typeof(myFunction)
typeof(myFunction)

for example

julia> test(x) = false
julia> test(x::typeof(length)) = true
julia> test(sizeof)
false
julia> test(length)
true

I mean, it should have returned like the following:

julia> typeof(myFunction)
Function

I do not quite understand what do you mean exactly.

typeof(myFunction) does not return Function, it returns the type of myFunction which is written
typeof(myFunction)” because each function has its own type (unlike many data structures).

You can use Function: isa(myFunction, Function) is true.

also supertype(typeof(myFunction)) == Function

2 Likes

You mean Function is a super type of all the self-defined functions? Could you give some examples?

Function is the immediate supertype of all the functions you use, including self-defined ones.

super(x) = supertype( typeof(x) )

super(sizeof) == Function
super(string) == Function

test(x) = true
add(x,y) = x+y

super(test) == Function
super(add) == Function
5 Likes