nextgen MLStyle: Generic Algebraic Data Type + Pattern Match
MIT License
Moshi is the pattern in Chinese (模式). This package is the refactor of MLStyle with
@match
@data
@derive
from rust[!IMPORTANT]
This project is in the early stage of development. The macro syntax has been iterated acorss several packages including Expronicon, MLStyle. The syntax are mostly stable. However, the API and features are subject to change.
pkg> add Moshi
Here is a quick example of defining a simple algebraic data type:
using Moshi.Data: @data
@data Message begin
Quit
struct Move
x::Int
y::Int
end
Write(String)
ChangeColor(Int, Int, Int)
end
For pattern matching, if you already used MLStyle
, the syntax is very similar:
using Moshi.Match: @match
@match [1.0, 2, 3] begin
[1, xs::Float64...] => xs
end
@match (1, 2.0, "a") begin
(1, x::Int, y::String) => x
(1, x::Real, y::String) => y
end
MIT License