Stream: helpdesk (published)

Topic: Generic vs const-type-eval?


view this post on Zulip iago-lito (Jul 25 2025 at 11:35):

I often find myself hesitating between these two options:

struct A{B} end
eltype(A{B}) where {B} = B

method(a::A) = do_stuff_with(a, eltype(a))      # ?
method(a::A{B}) where {B} = do_stuff_with(a, B) # ?

What's the difference? What do they imply? Are there contexts in which I should prefer either over the other?

view this post on Zulip Jakob Nybo Nissen (Jul 25 2025 at 11:47):

They are the same in almost all cases, except:

The style guide recommends the former, so I say: Use that, unless you are in the edge cases where you need specialization, or in that weird subtyping edge case


Last updated: Aug 14 2025 at 04:51 UTC