# Pattern matching + Enum proposals

**URL:** <https://forum.modular.com/t/pattern-matching-enum-proposals/3473>\
**Category:** Language Design\
**Tags:** discussion\
**Created:** [September 7, 2026, 2:54am UTC](https://forum.modular.com/t/pattern-matching-enum-proposals/3473 "2026-09-07T02:54:29Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![clattner](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/clattner/32/201_2.png) [@clattner](https://forum.modular.com/u/clattner)\
**Post date:** [September 7, 2026, 6:43pm UTC](https://forum.modular.com/t/pattern-matching-enum-proposals/3473/13 "2026-09-07T18:43:16Z")

</div>

> [@mzaks](#):
>
> **1. Recursive enums**
> 
> Is there a story for defining recursive `enum`s? Swift handles this with the `indirect` keyword, which quietly inserts a box. Will Mojo have similar sugar, or go with a more explicit approach where we wrap the self-referencing value in a pointer type ourselves? I’d be happy with either, but it would be good to know which direction the proposal is leaning.

There is no proposed mechanic here - until the origin story bakes a bit more, I would like to avoid adding first class indirection. That said, I would hope that this would just be a “heap box” sort of thing, rather than a feature of enums. “Simple things that compose” are preferred over dedicated features IMO.

> [@mzaks](#):
>
> So it might make sense to let a declaration opt into a stricter guarantee, whether as a decorator, a trait, or a compile-time parameter, signalling to the compiler that this one has to stay niche-representable and that it should error out if it can’t.

Sure, I can see a use-case for “explicit layout control”. If/when structs get that, it would be natural for enums to have it as well (since enums would be sugar for structs). I don’t see a reason to do enums first.

> [@mzaks](#):
>
> Does it make sense for an array of enums to get a bit-packed internal representation based on the number of cases?

While appealing, I’m not aware of how to make this general purpose. The problem is that you want an instance of an enum to have a reliable in place memory representation - this is required to get references to it.

---

_[View the full topic](https://forum.modular.com/t/pattern-matching-enum-proposals/3473)._
