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

**URL:** <https://discourse.julialang.org/t/typeof-myfunction-does-not-work-for-a-self-defined-function-myfunction/24464>\
**Category:** General Usage\
**Created:** [May 22, 2019, 9:01am UTC](https://discourse.julialang.org/t/typeof-myfunction-does-not-work-for-a-self-defined-function-myfunction/24464 "2019-05-22T09:01:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [May 22, 2019, 9:01am UTC](https://discourse.julialang.org/t/typeof-myfunction-does-not-work-for-a-self-defined-function-myfunction/24464/1 "2019-05-22T09:01:10Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [May 22, 2019, 9:11am UTC](https://discourse.julialang.org/t/typeof-myfunction-does-not-work-for-a-self-defined-function-myfunction/24464/2 "2019-05-22T09:11:42Z")

</div>

What do you mean “does not work”?

The type of a function is written like that:

```julia
julia> typeof(myFunction)
typeof(myFunction)

```

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [May 22, 2019, 9:15am UTC](https://discourse.julialang.org/t/typeof-myfunction-does-not-work-for-a-self-defined-function-myfunction/24464/3 "2019-05-22T09:15:24Z")

</div>

for example

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

```

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [May 22, 2019, 9:19am UTC](https://discourse.julialang.org/t/typeof-myfunction-does-not-work-for-a-self-defined-function-myfunction/24464/4 "2019-05-22T09:19:06Z")

</div>

I mean, it should have returned like the following:

julia\> typeof(myFunction)  
Function

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [May 22, 2019, 9:19am UTC](https://discourse.julialang.org/t/typeof-myfunction-does-not-work-for-a-self-defined-function-myfunction/24464/5 "2019-05-22T09:19:33Z")

</div>

I do not quite understand what do you mean exactly.

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [May 22, 2019, 9:27am UTC](https://discourse.julialang.org/t/typeof-myfunction-does-not-work-for-a-self-defined-function-myfunction/24464/6 "2019-05-22T09:27:34Z")

</div>

`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`

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [May 22, 2019, 9:35am UTC](https://discourse.julialang.org/t/typeof-myfunction-does-not-work-for-a-self-defined-function-myfunction/24464/7 "2019-05-22T09:35:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [May 22, 2019, 9:39am UTC](https://discourse.julialang.org/t/typeof-myfunction-does-not-work-for-a-self-defined-function-myfunction/24464/8 "2019-05-22T09:39:12Z")

</div>

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

```julia
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
```
