# Partial parametric methods?

**URL:** <https://discourse.julialang.org/t/partial-parametric-methods/28911>\
**Category:** General Usage\
**Created:** [September 18, 2019, 7:03pm UTC](https://discourse.julialang.org/t/partial-parametric-methods/28911 "2019-09-18T19:03:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [September 18, 2019, 7:03pm UTC](https://discourse.julialang.org/t/partial-parametric-methods/28911/1 "2019-09-18T19:03:12Z")

</div>

Not sure if the title of the topic accurately reflects what I’m looking for, but this is what I have in mind:

- I have a parametric type, `HashMap{T,R}` (it’s basically a custom `Dict{T,R}` type).

- I want to define methods such as `delete!`:

```julia
delete!(hm::HashMap, key)

```

- for `delete!` I do not have the value (and its type), but I do have the key - and I would like to constrain the type of key to `T`, producing something like

```julia
delete!(hm::HashMap{T,_}, key::T) where {T}

```

Is this possible? Or is there any other way to do it? Is it at all useful or is it best to stick to non-parametric methods instead?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [September 18, 2019, 7:11pm UTC](https://discourse.julialang.org/t/partial-parametric-methods/28911/2 "2019-09-18T19:11:57Z")

</div>

Does this work for your use case:

```julia
julia> foo(x::HashMap{T, X}, key::T) where {T, X} = ...

```

?

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [September 18, 2019, 7:16pm UTC](https://discourse.julialang.org/t/partial-parametric-methods/28911/3 "2019-09-18T19:16:59Z")

</div>

If you want to use the `_` notation just do

```julia
delete!(hm::HashMap{T,_}, key::T) where {T, _}

```

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [September 18, 2019, 7:21pm UTC](https://discourse.julialang.org/t/partial-parametric-methods/28911/4 "2019-09-18T19:21:17Z")

</div>

@rdeits Ah, OK, I understand - I was looking at the problem all wrong. The method is parametrized by both T and X because of the HashMap instance, and that’s where it gets the types from. Sure, makes total sense, thank you.

@Mason Thanks - it’s not so much about the name of the type parameters. I was just under the impression that the second type would be missing when invoking the method, not realising that it’s in fact provided by the HashMap instance.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [September 18, 2019, 10:15pm UTC](https://discourse.julialang.org/t/partial-parametric-methods/28911/5 "2019-09-18T22:15:01Z")

</div>

you don’t need to specify the second one at all, `delete!(hm::HashMap{T}, key::T) where T` is equivalent to `delete!(hm::HashMap{T,X} where X, key::T) where T`.

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [September 19, 2019, 7:19am UTC](https://discourse.julialang.org/t/partial-parametric-methods/28911/6 "2019-09-19T07:19:21Z")

</div>

Oh, lovely, this is actually what my query was about! I think such a definition much better captures the intent of the author (`X` is irrelevant in this context).
