# Multiple-dispatch depending on output type?

**URL:** https://discourse.julialang.org/t/multiple-dispatch-depending-on-output-type/7639
**Category:** Internals & Design
**Created:** [December 9, 2017, 12:35am UTC](https://discourse.julialang.org/t/multiple-dispatch-depending-on-output-type/7639 "2017-12-09T00:35:08Z")
**Posts on this page:** 2
**Page:** 2

<div class="post-metadata">

### Author: ![sgaure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sgaure/32/14779_2.png) [@sgaure](https://discourse.julialang.org/u/sgaure)
#### Post date: [October 31, 2024, 1:30pm UTC](https://discourse.julialang.org/t/multiple-dispatch-depending-on-output-type/7639/21 "2024-10-31T13:30:33Z")

</div>

> [@world-peace](#):
>
> Can you get the same behavior by “overloading” `sqrt` (providing a method for `sqrt`) with a method which takes an argument `type` as the first argument?
> 
> ```julia
> sqrt(some_type, value)
> if some_type isa GAlgebra ...
> 
> ```
> 
> Perhaps this is what was being suggested and I just missed the point being made or otherwise misunderstood here?

This is exactly what was suggested. Typically in julia you will not use a construction like,

```julia
function sqrt(type, value)
    if type <: GAlgebra
        ...
    else
        ...
    end
end

```

rather you will make a

```julia
function sqrt(::Type{GAlgebra}, value)
    ...
end

```

Even though in the first case the if-test may be eliminated by constant folding/propagation, the second case is cleaner. The if-test is gone, it’s taken care of directly by the compile-time dispatch.

---

<div class="post-metadata">

### Author: ![world-peace](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@world-peace](https://discourse.julialang.org/u/world-peace)
#### Post date: [October 31, 2024, 3:00pm UTC](https://discourse.julialang.org/t/multiple-dispatch-depending-on-output-type/7639/22 "2024-10-31T15:00:47Z")

</div>

Right, thank you for that explanation - it’s now clear to me what was meant by this

```julia
function sqrt(::Type{GAlgebra}, value)
    ...
end

```

[Previous page](https://discourse.julialang.org/t/multiple-dispatch-depending-on-output-type/7639.md?page=1)
