# \#traits

**URL:** https://discourse.julialang.org/tag/traits/380.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [ANN: TraitInterfaces.jl - explicit interfaces in Julia](https://discourse.julialang.org/t/ann-traitinterfaces-jl-explicit-interfaces-in-julia/131151)

<div class="topic-metadata">

**Author:** [@kris-brown](https://discourse.julialang.org/u/kris-brown)\
**Replies:** 0\
**Last updated:** [July 28, 2025, 11:01pm UTC](https://discourse.julialang.org/t/ann-traitinterfaces-jl-explicit-interfaces-in-julia/131151 "2025-07-28T23:01:53Z")

</div>

Hi, I’m pleased to share TraitInterfaces.jl. It provides an @interface macro to declare interfaces and an @instance macro to declare implementations of those interfaces. These implementations are identified with Julia va…

---

## [Interfaces/traits in julia 2.0 and multiple inheritance](https://discourse.julialang.org/t/interfaces-traits-in-julia-2-0-and-multiple-inheritance/124011)

<div class="topic-metadata">

**Author:** [@serhii](https://discourse.julialang.org/u/serhii)\
**Replies:** 37\
**Last updated:** [May 7, 2025, 5:53pm UTC](https://discourse.julialang.org/t/interfaces-traits-in-julia-2-0-and-multiple-inheritance/124011 "2025-05-07T17:53:09Z")

</div>

Recently, I started programming in Rust, and like many others, I noticed how powerful the design language and solutions around traits can be. This prompted me to investigate Julia’s interface and trait-related packages: …

---

## [Why did Julia choose nominal typing over structural typing/traits?](https://discourse.julialang.org/t/why-did-julia-choose-nominal-typing-over-structural-typing-traits/122517)

<div class="topic-metadata">

**Author:** [@serhii](https://discourse.julialang.org/u/serhii)\
**Replies:** 29\
**Last updated:** [November 16, 2024, 3:12pm UTC](https://discourse.julialang.org/t/why-did-julia-choose-nominal-typing-over-structural-typing-traits/122517 "2024-11-16T15:12:40Z")

</div>

I’ve been thinking about Julia’s type system design, particularly how it uses nominal typing rather than structural typing or a trait-based system. I’m curious about the historical and technical reasons behind this choic…

---

## [Module parameters and run-time efficiency](https://discourse.julialang.org/t/module-parameters-and-run-time-efficiency/119505)

<div class="topic-metadata">

**Author:** [@jhidding](https://discourse.julialang.org/u/jhidding)\
**Replies:** 3\
**Last updated:** [September 17, 2024, 3:17pm UTC](https://discourse.julialang.org/t/module-parameters-and-run-time-efficiency/119505 "2024-09-17T15:17:57Z")

</div>

Hi, I want to perform dispatch based on functions of the same name within a module. There’s two ways to go about it: having a function f(m::Module,...) or defining a trait type and saying f(::Type{Mod{M}}, ...) where M. …

---

## [Holy traits vs "boolean traits"](https://discourse.julialang.org/t/holy-traits-vs-boolean-traits/111954)

<div class="topic-metadata">

**Author:** [@marcpabst](https://discourse.julialang.org/u/marcpabst)\
**Replies:** 9\
**Last updated:** [July 21, 2024, 5:09pm UTC](https://discourse.julialang.org/t/holy-traits-vs-boolean-traits/111954 "2024-07-21T17:09:06Z")

</div>

I’ve been exploring how holy traits are typically implemented in Julia, often seeing patterns like the following: SomeTrait(x::Type) = B() SomeTrait(::Type{\<:T}) = A() somefunc(x::T) where {T} = somefunc(SomeTrait(T), …

---

## [How can I use a Holy trait defined in a module outside of it?](https://discourse.julialang.org/t/how-can-i-use-a-holy-trait-defined-in-a-module-outside-of-it/116408)

<div class="topic-metadata">

**Author:** [@paalon](https://discourse.julialang.org/u/paalon)\
**Replies:** 3\
**Last updated:** [June 30, 2024, 7:49am UTC](https://discourse.julialang.org/t/how-can-i-use-a-holy-trait-defined-in-a-module-outside-of-it/116408 "2024-06-30T07:49:28Z")

</div>

I’m studying Julia’s Holy traits along with traits in Rust, Scala and the original traits paper, “Traits: A Mechanism for Fine-grained Reuse”. I want to use a trait Color defined in ColorModule outside of its module. I w…

---

## [Which is better for traits? Subtyping vs parametric typing](https://discourse.julialang.org/t/which-is-better-for-traits-subtyping-vs-parametric-typing/115899)

<div class="topic-metadata">

**Author:** [@paalon](https://discourse.julialang.org/u/paalon)\
**Replies:** 3\
**Last updated:** [June 20, 2024, 10:52am UTC](https://discourse.julialang.org/t/which-is-better-for-traits-subtyping-vs-parametric-typing/115899 "2024-06-20T10:52:36Z")

</div>

I want to define traits (I don’t know so much about traits but perhaps traits). I know 2 ways. Abstract type and subtypes: abstract type YAMLVersion end struct YAMLV1\_1 \<: YAMLVersion end struct YAMLV1\_2 \<: YAMLVersi…

---

## [Traits and type piracy](https://discourse.julialang.org/t/traits-and-type-piracy/112516)

<div class="topic-metadata">

**Author:** [@pat-alt](https://discourse.julialang.org/u/pat-alt)\
**Replies:** 3\
**Last updated:** [April 4, 2024, 12:27pm UTC](https://discourse.julialang.org/t/traits-and-type-piracy/112516 "2024-04-04T12:27:31Z")

</div>

TLDR: I’m defining a trait in a meta package A and trying to assign the trait in a package B that imports A. This causes type piracy and I don’t know how to resolve it. Background: Inspired by other examples such as MLJ…

---

## [Why traits?](https://discourse.julialang.org/t/why-traits/105591)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 5\
**Last updated:** [November 19, 2023, 12:30pm UTC](https://discourse.julialang.org/t/why-traits/105591 "2023-11-19T12:30:20Z")

</div>

I’ve been trying to teach my students traits, only to realize that there is something I don’t fully understand. Is there any different between these two approaches to dispatch? struct A end struct B end ## Holy trait …

---

## [Are hasmethod and applicable recommended for defining traits now?](https://discourse.julialang.org/t/are-hasmethod-and-applicable-recommended-for-defining-traits-now/97533)

<div class="topic-metadata">

**Author:** [@zsunberg](https://discourse.julialang.org/u/zsunberg)\
**Replies:** 2\
**Last updated:** [April 17, 2023, 12:21am UTC](https://discourse.julialang.org/t/are-hasmethod-and-applicable-recommended-for-defining-traits-now/97533 "2023-04-17T00:21:58Z")

</div>

If I understand correctly, as of Julia 1.10, according to this PR, it will be possible to statically infer the output of hasmethod and applicable. Previously, things like static\_hasmethod from Tricks.jl seemed to be not …

---

## [IsIndexed trait](https://discourse.julialang.org/t/isindexed-trait/91741)

<div class="topic-metadata">

**Author:** [@freeman](https://discourse.julialang.org/u/freeman)\
**Replies:** 2\
**Last updated:** [April 8, 2023, 8:35pm UTC](https://discourse.julialang.org/t/isindexed-trait/91741 "2023-04-08T20:35:09Z")

</div>

I’m trying to understand is something like a IsIndexed trait exists already, or not. This trait would be true for all things which: are collections and for each element there is\[1\] one key which has O(1) access. The …

---

## [RFC: Language Support for Traits — Yay or Nay?](https://discourse.julialang.org/t/rfc-language-support-for-traits-yay-or-nay/93914)

<div class="topic-metadata">

**Author:** [@uniment](https://discourse.julialang.org/u/uniment)\
**Replies:** 45\
**Last updated:** [February 8, 2023, 1:51am UTC](https://discourse.julialang.org/t/rfc-language-support-for-traits-yay-or-nay/93914 "2023-02-08T01:51:46Z")

</div>

A repeated gripe I see from the local gray-hairs about Julia’s type system pertains to the lack of language support for multiple inheritance through traits—to manage those pesky behaviors that fall outside the type hiera…

---

## [Dispatch over element type](https://discourse.julialang.org/t/dispatch-over-element-type/93769)

<div class="topic-metadata">

**Author:** [@iago-lito](https://discourse.julialang.org/u/iago-lito)\
**Replies:** 14\
**Last updated:** [January 30, 2023, 8:54pm UTC](https://discourse.julialang.org/t/dispatch-over-element-type/93769 "2023-01-30T20:54:02Z")

</div>

I find the following code too restrictive: function f(collection::Vector{Int64}) for i in collection println("Integer: $i") end end function f(collection::Vector{String}) for s in collection …

---

## [Question on Idiomatic Julia, Traits, and Types](https://discourse.julialang.org/t/question-on-idiomatic-julia-traits-and-types/93484)

<div class="topic-metadata">

**Author:** [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)\
**Replies:** 6\
**Last updated:** [January 25, 2023, 7:36am UTC](https://discourse.julialang.org/t/question-on-idiomatic-julia-traits-and-types/93484 "2023-01-25T07:36:39Z")

</div>

I’m trying to better learn and understand how to write idiomatic Julia. Please consider the following example. I have a some types defined as follows. abstract type MyAbstractType end Base.@kwdef struct MyStruct\_1D \<:…

---

## [Combining SimpleTraits.jl traits on one type](https://discourse.julialang.org/t/combining-simpletraits-jl-traits-on-one-type/73644)

<div class="topic-metadata">

**Author:** [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Replies:** 5\
**Last updated:** [April 8, 2022, 2:49pm UTC](https://discourse.julialang.org/t/combining-simpletraits-jl-traits-on-one-type/73644 "2022-04-08T14:49:37Z")

</div>

I recently got a little into SimpleTraits - and I like it quite well. But I have a question considering the combination of traits. Consider the following MWE (just noticed, maybe AbstractA is not necessary in general) u…

---

## [Trait dispatch causing allocations](https://discourse.julialang.org/t/trait-dispatch-causing-allocations/75742)

<div class="topic-metadata">

**Author:** [@jg-854](https://discourse.julialang.org/u/jg-854)\
**Replies:** 9\
**Last updated:** [February 4, 2022, 2:06pm UTC](https://discourse.julialang.org/t/trait-dispatch-causing-allocations/75742 "2022-02-04T14:06:51Z")

</div>

I am simulating electronic circuits and I have chosen to adopt a modular model which works on objects of type Component. A Component can be a Resistor, Capacitor, or even a Serial/Parallel combination of Components. Th…

---

## [Deep dive detangling terms: multiple inheritance vs. traits](https://discourse.julialang.org/t/deep-dive-detangling-terms-multiple-inheritance-vs-traits/67110)

<div class="topic-metadata">

**Author:** [@bgroenks](https://discourse.julialang.org/u/bgroenks)\
**Replies:** 10\
**Last updated:** [August 24, 2021, 1:11pm UTC](https://discourse.julialang.org/t/deep-dive-detangling-terms-multiple-inheritance-vs-traits/67110 "2021-08-24T13:11:48Z")

</div>

I did not read issue 5, I am just expressing my view on this subject. I don’t agree with this use of the phrase “multiple inheritance”. In PL theory, traits and inheritance are separate concepts, though they can be use…

---

## [Why use subtypes instead of traits and duck typing?](https://discourse.julialang.org/t/why-use-subtypes-instead-of-traits-and-duck-typing/59146)

<div class="topic-metadata">

**Author:** [@regier2302](https://discourse.julialang.org/u/regier2302)\
**Replies:** 32\
**Last updated:** [April 15, 2021, 3:58pm UTC](https://discourse.julialang.org/t/why-use-subtypes-instead-of-traits-and-duck-typing/59146 "2021-04-15T15:58:50Z")

</div>

I have been tinkering with Julia and I am now trying to design a moderate-sized project. However, I have been struggling to come up with a type hierarchy and I realized that, in Julia, I don’t know why you should subtype…

---

## [\[ANN\] BinaryTraits.jl - a new traits package](https://discourse.julialang.org/t/ann-binarytraits-jl-a-new-traits-package/37475)

<div class="topic-metadata">

**Author:** [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Replies:** 27\
**Last updated:** [November 6, 2020, 11:15am UTC](https://discourse.julialang.org/t/ann-binarytraits-jl-a-new-traits-package/37475 "2020-11-06T11:15:28Z")

</div>

Hi everyone, I would like to announce BinaryTraits.jl, a new traits package that focuses on usability and interface specification. You can find documentation from the project repo as usual. In addition, I have provide…

---

## ["Traits" which may be defined on types or values?](https://discourse.julialang.org/t/traits-which-may-be-defined-on-types-or-values/48919)

<div class="topic-metadata">

**Author:** [@evanfields](https://discourse.julialang.org/u/evanfields)\
**Replies:** 10\
**Last updated:** [October 24, 2020, 6:08pm UTC](https://discourse.julialang.org/t/traits-which-may-be-defined-on-types-or-values/48919 "2020-10-24T18:08:22Z")

</div>

I’m trying to learn about \[Holy\] traits for the first time. It seems that in the classic implementation, an object’s traitfulness depends only on that object’s type, not value. For example, maybe I want to classify certa…

---

## [Types vs traits for dispatch](https://discourse.julialang.org/t/types-vs-traits-for-dispatch/46296)

<div class="topic-metadata">

**Author:** [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Replies:** 7\
**Last updated:** [September 10, 2020, 7:57am UTC](https://discourse.julialang.org/t/types-vs-traits-for-dispatch/46296 "2020-09-10T07:57:00Z")

</div>

I recently learned about the Tim Holy Trait Trick as one way to dispatch on “groups” of types outside of a type hierarchy. This seems more general to me than dispatch based on type hierarchy, but I’m not sure. Are there…

---

## [What's the best way to dispatch on an \_iterable\_ trait?](https://discourse.julialang.org/t/whats-the-best-way-to-dispatch-on-an-iterable-trait/42084)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 15\
**Last updated:** [July 4, 2020, 3:38pm UTC](https://discourse.julialang.org/t/whats-the-best-way-to-dispatch-on-an-iterable-trait/42084 "2020-07-04T15:38:30Z")

</div>

I find that it’s quite common for me to write a function that requires the input to be iterable. But I don’t think there is a good way to restrict it to that. I think I would love to see a trait system built into Julia e…

---

## [How to subtype a type alias?](https://discourse.julialang.org/t/how-to-subtype-a-type-alias/24050)

<div class="topic-metadata">

**Author:** [@Olivier\_Merchiers](https://discourse.julialang.org/u/Olivier_Merchiers)\
**Replies:** 13\
**Last updated:** [June 30, 2020, 9:42pm UTC](https://discourse.julialang.org/t/how-to-subtype-a-type-alias/24050 "2020-06-30T21:42:01Z")

</div>

Hello everyone, I have a struct: struct MyType data :: Int end Now I want to create a vector of such structs: const MyVector = Vector{MyType} This works fine because I can make methods that dispatch on MyVector. …

---

## [Protocols/Interfaces/Traits... or: The "what to implement problem"](https://discourse.julialang.org/t/protocols-interfaces-traits-or-the-what-to-implement-problem/40137)

<div class="topic-metadata">

**Author:** [@FHell](https://discourse.julialang.org/u/FHell)\
**Replies:** 10\
**Last updated:** [June 2, 2020, 2:22pm UTC](https://discourse.julialang.org/t/protocols-interfaces-traits-or-the-what-to-implement-problem/40137 "2020-06-02T14:22:35Z")

</div>

Hello everyone, I am interested in picking up the “what to implement problem” of defining interfaces/protocols in Julia. In my view the broad issue is: How do I encode invariants and expectations of my code. This is cri…

---

## [Announcing Traits.jl - a revival of Julia traits](https://discourse.julialang.org/t/announcing-traits-jl-a-revival-of-julia-traits/35683)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 21\
**Last updated:** [April 11, 2020, 6:52am UTC](https://discourse.julialang.org/t/announcing-traits-jl-a-revival-of-julia-traits/35683 "2020-04-11T06:52:24Z")

</div>

Dear Julia community, Today I want to announce a package of mine, GitHub - schlichtanders/Traits.jl: traits for julia: dispatch on whatever you want After more than a year of intense experimenting with traits in Julia,…

---

## [Defining traits on functions using macros](https://discourse.julialang.org/t/defining-traits-on-functions-using-macros/36210)

<div class="topic-metadata">

**Author:** [@MaximeBouton](https://discourse.julialang.org/u/MaximeBouton)\
**Replies:** 10\
**Last updated:** [March 20, 2020, 9:19am UTC](https://discourse.julialang.org/t/defining-traits-on-functions-using-macros/36210 "2020-03-20T09:19:28Z")

</div>

Hello, I am trying to use traits on functions and I would like to define the trait automatically based on existing methods. I have several traits like EntityFeature and FrameFeature and a function featuretype(::typeof(…

---

## [Collection of objects with a trait](https://discourse.julialang.org/t/collection-of-objects-with-a-trait/33863)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 6\
**Last updated:** [January 28, 2020, 6:12pm UTC](https://discourse.julialang.org/t/collection-of-objects-with-a-trait/33863 "2020-01-28T18:12:56Z")

</div>

Has anyone given some thought how to work with collections of objects that have a (set of) trait(s)? How to create, maintain, iterate… What would a Base.iterate extension look like?

---

## [TraitWrapper - an idea for developing a traits based system](https://discourse.julialang.org/t/traitwrapper-an-idea-for-developing-a-traits-based-system/31179)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 9\
**Last updated:** [November 25, 2019, 4:57am UTC](https://discourse.julialang.org/t/traitwrapper-an-idea-for-developing-a-traits-based-system/31179 "2019-11-25T04:57:47Z")

</div>

I read with interests The Emergent Features of JuliaLang: Part II - Traits and have been thinking about traits lately. I think I understand how Holy Traits work but I feel unsatisfied with it. The examples and the blogs…

---

## [Make an existing type a child of an abstract type](https://discourse.julialang.org/t/make-an-existing-type-a-child-of-an-abstract-type/28162)

<div class="topic-metadata">

**Author:** [@zsoerenm](https://discourse.julialang.org/u/zsoerenm)\
**Replies:** 3\
**Last updated:** [August 29, 2019, 2:26pm UTC](https://discourse.julialang.org/t/make-an-existing-type-a-child-of-an-abstract-type/28162 "2019-08-29T14:26:25Z")

</div>

Is it possible to make an existing type a child of an abstract type? Something like this? using StaticArrays abstract type Abstract3DVector end struct type SVector{3} \<: Abstract3DVector end Unfortunately it does not …

---

## [Trait inheritance](https://discourse.julialang.org/t/trait-inheritance/21021)

<div class="topic-metadata">

**Author:** [@datnamer](https://discourse.julialang.org/u/datnamer)\
**Replies:** 4\
**Last updated:** [February 20, 2019, 8:52pm UTC](https://discourse.julialang.org/t/trait-inheritance/21021 "2019-02-20T20:52:36Z")

</div>

Is it possible to dispatch on a trait inheritance hierarchy without invoking dynamic dispatch?

[Next page](https://discourse.julialang.org/tag/traits/380.md?match_all_tags=true&page=1&tags%5B%5D=traits)
