# Holy traits vs "boolean traits"

**URL:** <https://discourse.julialang.org/t/holy-traits-vs-boolean-traits/111954>\
**Category:** General Usage\
**Tags:** traits\
**Created:** [March 21, 2024, 9:36pm UTC](https://discourse.julialang.org/t/holy-traits-vs-boolean-traits/111954 "2024-03-21T21:36:15Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [March 22, 2024, 8:31am UTC](https://discourse.julialang.org/t/holy-traits-vs-boolean-traits/111954/6 "2024-03-22T08:31:39Z")

</div>

See also

> [@Why traits?](https://discourse.julialang.org/t/why-traits/105591):
>
> 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 trait1(::A) = Val(true) trait1(::B) = Val(false) f(x) = f(x, trait1(x)) f(x, ::Val{true}) = π f(x, ::Val{false}) = "pi" ## Type-inferrable if-else trait2(::A) = true trait2(::B) = false g(x) = trait2(x) ? π : "pi" Both make @code\_warntype happy, and while I know the first one …

---

_[View the full topic](https://discourse.julialang.org/t/holy-traits-vs-boolean-traits/111954)._
