# Interval not implementing 'Comparable' trait

**URL:** <https://forum.modular.com/t/interval-not-implementing-comparable-trait/2523>\
**Category:** Mojo\
**Tags:** discussion\
**Created:** [December 14, 2025, 8:32pm UTC](https://forum.modular.com/t/interval-not-implementing-comparable-trait/2523 "2025-12-14T20:32:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@Brandon](https://forum.modular.com/u/Brandon)\
**Post date:** [December 14, 2025, 8:32pm UTC](https://forum.modular.com/t/interval-not-implementing-comparable-trait/2523/1 "2025-12-14T20:32:12Z")

</div>

According to the [Mojo Reference on Interval](https://docs.modular.com/mojo/stdlib/collections/interval/Interval/#implemented-traits) it does not implement the `Comparable` trait, even though it implements the required methods (` __lt__ ` and ` __eq__ `). Why is that?

This becomes apparent when trying to sort a list of intervals: calling `sort` on a list of `Interval` objects results in an error (`no matching function in call to 'sort'`).

To validate my understanding, I created a small wrapper type around `Interval`. When I explicitly declare that this wrapper implements `Comparable`, sorting works as expected. If I omit `Comparable`, I get the same error as with plain `Interval`, despite defining `lt` and `eq`.

Here is a minimal example illustrating the behavior:

```auto
from collections.interval import Interval

@fieldwise_init
struct IntervalWrapper(Copyable, Movable, Comparable):
    var interval: Interval[Int]

    fn __lt__ (self, other: IntervalWrapper) -> Bool:
        return self.interval < other.interval

    fn __eq__ (self, other: IntervalWrapper) -> Bool:
        return self.interval == other.interval

fn main() raises:
    var intervals = [IntervalWrapper(Interval(1,5)), IntervalWrapper(Interval(0,3)), IntervalWrapper(Interval(4,6))]
    sort(intervals)

    var pure_intervals = [Interval(1,5), Interval(0,3), Interval(4,6)]
    sort(pure_intervals)

```

---

<div class="post-metadata">

**Author:** ![melodyogonna](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/melodyogonna/32/33_2.png) [@melodyogonna](https://forum.modular.com/u/melodyogonna)\
**Post date:** [December 15, 2025, 9:35am UTC](https://forum.modular.com/t/interval-not-implementing-comparable-trait/2523/2 "2025-12-15T09:35:13Z")

</div>

I think this should be an issue on GitHub

---

<div class="post-metadata">

**Author:** ![duck\_tape](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/duck_tape/32/432_2.png) [@duck\_tape](https://forum.modular.com/u/duck_tape)\
**Post date:** [December 15, 2025, 3:56pm UTC](https://forum.modular.com/t/interval-not-implementing-comparable-trait/2523/3 "2025-12-15T15:56:04Z")

</div>

> [@Brandon](#):
>
> es apparent when trying to sort a list of intervals: calling `sort` on a list of `Interval` objects results in an error (`no matching function in call to 'sort'`).
> 
> To validate my understanding, I created a small wrapper type around `Interval`. When I explicitly declare that this wrapper implements `Comparable`, sorting works as expected. If I omit `Comparable`, I get the same error as with plain `Interval`, despite defining `lt` and `e`

Implicit trait conformance was removed a while back and I guess that the Interval stuff never got updated to explicitly conform. @melodyogonna is right, this should just be a github issue.

---

<div class="post-metadata">

**Author:** ![Brandon](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@Brandon](https://forum.modular.com/u/Brandon)\
**Post date:** [December 15, 2025, 4:22pm UTC](https://forum.modular.com/t/interval-not-implementing-comparable-trait/2523/4 "2025-12-15T16:22:01Z")

</div>

Thank you, I will create a GitHub Issue.

---

<div class="post-metadata">

**Author:** ![christoph\_schlumpf](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/christoph_schlumpf/32/274_2.png) [@christoph\_schlumpf](https://forum.modular.com/u/christoph_schlumpf)\
**Post date:** [December 20, 2025, 4:33pm UTC](https://forum.modular.com/t/interval-not-implementing-comparable-trait/2523/5 "2025-12-20T16:33:31Z")

</div>

Here you go: [[stdlib][fix] Add `Comparable` trait to `Interval` by christoph-schlumpf · Pull Request #5692 · modular/modular · GitHub](https://github.com/modular/modular/pull/5692)
