# Is dispatch on another type's parameter (::NotMyType{MyType}) piracy?

**URL:** <https://discourse.julialang.org/t/is-dispatch-on-another-types-parameter-notmytype-mytype-piracy/110797>\
**Category:** General Usage\
**Created:** [February 26, 2024, 5:16pm UTC](https://discourse.julialang.org/t/is-dispatch-on-another-types-parameter-notmytype-mytype-piracy/110797 "2024-02-26T17:16:47Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [February 26, 2024, 4:05pm UTC](https://discourse.julialang.org/t/is-dispatch-on-another-types-parameter-notmytype-mytype-piracy/110797/2 "2024-02-26T16:05:50Z")

</div>

> [@Unsure about properties](https://discourse.julialang.org/t/unsure-about-properties/110756/11):
>
> Actually, does this follow?

I think it does (but I’m no authority). When you implement a new type `SomeType{T}` and define functions to manipulate it, you need to know that these functions do what you wrote, also internally, not just at the surface exposed to the user.

Consider this example:

```julia
mutable struct S{T}
    x::T
    y::T
    a::Union{Missing,T} # value to be cached
    S(x::T,y::T) where T = new{T}(x, y, missing)
end

function get_a(s::S)
    if ismissing(s.a)
        s.a = expensive_function(s.x, s.y)
    end
    return s.a
end

function get_b(s::S)
    get_a(s) # Make sure `a` is cached
    return s.a * s.a;
end

```

I don’t want to document that `get_b` is going to call `get_a` to populate the cached value of `a`. This is all internal stuff, but I should be able to depend on it when I implement my own functions on my own types. Also in the case of parametric types. So it makes sense to me that users are not allowed to define `get_a(s::S{CustomType})` even if they own `CustomType`.

Of course it’s fine if I document that it’s allowed (as in the `convert` case).

---

_[View the full topic](https://discourse.julialang.org/t/is-dispatch-on-another-types-parameter-notmytype-mytype-piracy/110797)._
