# What is typeof(fun)?

**URL:** <https://discourse.julialang.org/t/what-is-typeof-fun/33523>\
**Category:** General Usage\
**Created:** [January 18, 2020, 3:44pm UTC](https://discourse.julialang.org/t/what-is-typeof-fun/33523 "2020-01-18T15:44:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Post date:** [January 18, 2020, 3:44pm UTC](https://discourse.julialang.org/t/what-is-typeof-fun/33523/1 "2020-01-18T15:44:56Z")

</div>

when I `methods(Base.map)`, I see something like:

```julia
[1] map(::typeof(zero), A::BitArray) in Base at bitarray.jl:1659

```

what is `typeof(zero)`? indeed, I found that:

```julia
julia> f(x) = 2x
f (generic function with 1 method)

julia> typeof(f)
typeof(f)

julia> typeof(f) <: Function
true

julia> typeof(f) isa DataType
true

julia> f isa Function
true

```

it’s quite strange to me: why `typeof(f)` not return `Function`? official docs mentions nothing about it.

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [January 18, 2020, 4:00pm UTC](https://discourse.julialang.org/t/what-is-typeof-fun/33523/2 "2020-01-18T16:00:28Z")

</div>

In this context, `map` is restricted to methods of `zero`. In Julia, every function has its own type . When you specialize a method for a given function, you need to restrict allowed input argument so the `typeof(fun)`. `Function` is supertype of all functions and it is abstract.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [January 18, 2020, 4:37pm UTC](https://discourse.julialang.org/t/what-is-typeof-fun/33523/3 "2020-01-18T16:37:37Z")

</div>

Note that if `typeof(f)` were `Function`, functions like `map` and `broadcast` would have to be type unstable, because they couldn’t specialize on the particular functions you’re passing to them.

For writing specific methods that handle a particular function in a special way (eg, `zero`), knowing that the type of `zero` is `typeof(zero)` is a lot easier than if it were some mangled name.

---

<div class="post-metadata">

**Author:** ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Post date:** [January 19, 2020, 1:31am UTC](https://discourse.julialang.org/t/what-is-typeof-fun/33523/4 "2020-01-19T01:31:25Z")

</div>

thanks.

> [@tomaklutfu](#):
>
> In Julia, every function has its own type

as I remembered, official docs does not mention it?

---

<div class="post-metadata">

**Author:** ![colintbowers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colintbowers/32/8033_2.png) [@colintbowers](https://discourse.julialang.org/u/colintbowers)\
**Post date:** [January 19, 2020, 9:04am UTC](https://discourse.julialang.org/t/what-is-typeof-fun/33523/5 "2020-01-19T09:04:10Z")

</div>

I gave a fairly detailed stack overflow response on exactly this question [here](https://stackoverflow.com/questions/52351852/puzzling-results-for-julia-typeof)

Cheers,

Colin

---

<div class="post-metadata">

**Author:** ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Post date:** [January 20, 2020, 1:57pm UTC](https://discourse.julialang.org/t/what-is-typeof-fun/33523/6 "2020-01-20T13:57:09Z")

</div>

I’ve just submitted the issue in [GitHub](https://github.com/JuliaLang/julia/issues/34445).
