# Method dispatch on function types with constructor

**URL:** <https://discourse.julialang.org/t/method-dispatch-on-function-types-with-constructor/48247>\
**Category:** General Usage\
**Tags:** zygote\
**Created:** [October 12, 2020, 5:58pm UTC](https://discourse.julialang.org/t/method-dispatch-on-function-types-with-constructor/48247 "2020-10-12T17:58:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![martenlienen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martenlienen/32/18572_2.png) [@martenlienen](https://discourse.julialang.org/u/martenlienen)\
**Post date:** [October 12, 2020, 5:58pm UTC](https://discourse.julialang.org/t/method-dispatch-on-function-types-with-constructor/48247/1 "2020-10-12T17:58:40Z")

</div>

I am using Zygote to autodiff some code and Zygote needs me to define an adjoint for some constructor. Following the docs, I went on to define an rrule with ChainRules but now I am stuck because it does not work. The problem is that rrule dispatches on function types like this

```julia
function rrule(::typeof(sin), x)
    # ...
end

```

The following does not work though

```julia
struct A
    a
end

function rrule(::typeof(A), a)
    # ...
end

```

because `typeof(A) == DataType` and not `typeof(A)` as it is for functions. Is there some syntax that lets me express to Julia that I am talking about the constructor/function `A` and not the struct `A`?

---

<div class="post-metadata">

**Author:** ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)\
**Post date:** [October 12, 2020, 6:46pm UTC](https://discourse.julialang.org/t/method-dispatch-on-function-types-with-constructor/48247/2 "2020-10-12T18:46:26Z")

</div>

I think you’re looking for `Type{A}`, a type whose only instance is `A` ([Types · The Julia Language](https://docs.julialang.org/en/v1/manual/types/#man-singleton-types)).

---

<div class="post-metadata">

**Author:** ![martenlienen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martenlienen/32/18572_2.png) [@martenlienen](https://discourse.julialang.org/u/martenlienen)\
**Post date:** [October 12, 2020, 6:59pm UTC](https://discourse.julialang.org/t/method-dispatch-on-function-types-with-constructor/48247/3 "2020-10-12T18:59:57Z")

</div>

That works, thanks a lot!
