Moshi.jl
Algebraic data types, pattern matching, and trait derivation for Julia.
模式 · Pattern matching for Julia
Moshi.jl
Type-stable ADTs, exhaustive pattern matching, and Rust-style derives — built for modern Julia.
example.jl
using Moshi.Data: @datausing Moshi.Match: @match
@data Shape begin Circle(Float64) Rect(Float64, Float64)end
area = @match shape begin Shape.Circle(r) => π * r^2 Shape.Rect(w, h) => w * hendThree macros, one toolkit
Why Moshi?
Section titled “Why Moshi?”Moshi (模式, móshì) brings ML-family patterns to Julia: sum types with @data, expressive @match, and @derive for common traits. It builds on ideas from MLStyle, SumTypes, and Expronicon.
using Moshi.Data: @datausing Moshi.Match: @matchusing Moshi.Derive: @derive
@data Expr begin Num(Int) Add(Self, Self) Mul(Self, Self)end
@derive Expr[Show, Hash, Eq]
eval = @match expr begin Expr.Num(n) => n Expr.Add(a, b) => eval(a) + eval(b) Expr.Mul(a, b) => eval(a) * eval(b)endGet started in 30 seconds
Section titled “Get started in 30 seconds”pkg> add MoshiThen head to the Quick Start guide or browse the API reference.