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

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

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

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, 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
37 Likes

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

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). :smiley:

2 Likes

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!

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

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

7 Likes

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 Unions.

updated benchmark on 1.10

on 1.11

6 Likes