# \[ANN\] Moshi v0.3 - the next-gen MLStyle, GADT, extensible pattern matching and more

**URL:** https://discourse.julialang.org/t/ann-moshi-v0-3-the-next-gen-mlstyle-gadt-extensible-pattern-matching-and-more/117613
**Category:** Package Announcements
**Tags:** announcement, pattern-matching
**Created:** [July 29, 2024, 9:06pm UTC](https://discourse.julialang.org/t/ann-moshi-v0-3-the-next-gen-mlstyle-gadt-extensible-pattern-matching-and-more/117613 "2024-07-29T21:06:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)
#### Post date: [July 29, 2024, 9:06pm UTC](https://discourse.julialang.org/t/ann-moshi-v0-3-the-next-gen-mlstyle-gadt-extensible-pattern-matching-and-more/117613/1 "2024-07-29T21:06:03Z")

</div>

This work has been iterating for about three years across multiple packages, from design to implementation. Now, it’s converging, so I’m very excited to announce a pre-alpha version for people to try out first.

Please read my blog post for a little introduction and story behind the development

> **[Moshi - pattern matching and algebraic data types for Julia | 罗秀哲｜Xiu-Zhe...](https://rogerluo.dev/posts/moshi/)**
>
> Announcing Moshi, the next-gen MLStyle. Pattern matching and algebraic data types for Julia.

Please refer to the documentation about the package, GADTs, and pattern matching. I included a small introduction for the unfamiliar.

> **[Welcome to Moshi](https://rogerluo.dev/Moshi.jl/)**
>
> Pattern match with & without generic algebraic data types in Julia!

Happy coding!

## Acknowledgement

Thanks to all the following people from the community and their work inspired Moshi

- @thautwarm, for various discussions in the past four years around MLStyle
- @Mason for inspiring work in [SumTypes](https://github.com/MasonProtter/SumTypes.jl), and for various discussions on Slack.
- @jameson for discussion about type piracy on `getproperty` and memory layout of `Union` during JuliaCon 2023 and GitHub.
- @YingboMa for discussion about use cases in SymbolicUtils and use cases in JuliaHub on pattern matching

---

<div class="post-metadata">

### Author: ![nandoconde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nandoconde/32/19497_2.png) [@nandoconde](https://discourse.julialang.org/u/nandoconde)
#### Post date: [July 29, 2024, 9:57pm UTC](https://discourse.julialang.org/t/ann-moshi-v0-3-the-next-gen-mlstyle-gadt-extensible-pattern-matching-and-more/117613/2 "2024-07-29T21:57:29Z")

</div>

Great refactoring effort, thanks a lot!

I have taken a look at the blog post and the GitHub page but I couldn’t find a reference/comparison with the latest (and quite performant) package on Union Types: [GitHub - JuliaDynamics/DynamicSumTypes.jl: Easy-to-use sum types in Julia](https://github.com/JuliaDynamics/DynamicSumTypes.jl)

I know that it does not support full pattern matching, but it may be worth including some performance comparisons against it (in large arrays, in terms of speed/size). 😃

---

<div class="post-metadata">

### Author: ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)
#### Post date: [August 4, 2024, 10:18pm UTC](https://discourse.julialang.org/t/ann-moshi-v0-3-the-next-gen-mlstyle-gadt-extensible-pattern-matching-and-more/117613/3 "2024-08-04T22:18:08Z")

</div>

Hi, yes, there was a benchmark in the repository, actually. There is one last overhead I wanted to get rid of before showing a benchmark (tho it was only slower than my baseline implementation). And it turns out to be a trivial codegen duplication.

Now the final benchmark shows Moshi has the same overhead as a manual implementation of (G)ADT and is the fastest implementation (basically no overhead, v0.3.1) of (G)ADT in Julia!

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/d/9db931e94ed490c81bc9a32955df0d2f38dc0e8c.png)

For more details about the benchmark, now it is included in the documentation

> **[Benchmarks](https://rogerluo.dev/Moshi.jl/data/benchmark/)**
>
> A comparision of performance of ADTs between Moshi and other packages

Oops, the legend title “speedup” should be “slowdown” in case of confusion!

---

<div class="post-metadata">

### Author: ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)
#### Post date: [August 5, 2024, 3:36pm UTC](https://discourse.julialang.org/t/ann-moshi-v0-3-the-next-gen-mlstyle-gadt-extensible-pattern-matching-and-more/117613/4 "2024-08-05T15:36:15Z")

</div>

It turns out I had a small mistake on DynamicSumTypes benchmark, now it is slightly faster on 1.10 and is on par with Moshi on 1.11 (about 5% slower only). Julia 1.11 seems bringing a lot more optimization for `Union`s.

updated benchmark on 1.10

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/4/c4dac478e7eaff39bc841d3db65e3ec867a6d719.png)

on 1.11

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/a/6aa1e873eae32229eacf3f5fad4f57ab0efcf5b0.png)
