Skip to content

Welcome to Moshi

Pattern match with & without generic algebraic data types in Julia!

Next steps

Algebraic Data Type

Define your own algebraic data types with @data macro.

@data Message begin
Quit
struct Move
x::Int
y::Int
end
Write(String)
ChangeColor(Int, Int, Int)
end

Derive Macro

Derive other methods from your type definitions (normal Julia struct or @data) with @derive macro.

@derive Message[Show, Hash]

Pattern Matching

@match value begin
Message.Move(; x, y) => (x, y)
Message.Quit() => 0
Message.Write(msg) => msg
Message.ChangeColor(a) => a
end