MLStyle variadic match ast

This code works

using MLStyle, MLStyle.Modules.AST
@match :( (a::Foo, b::Bar) ) begin
    :($n1::$t1, $n2::$t2) => (n1,n2)
end

but I want to do this with arbitrarily many variables, not just 2. I tried using ... but it failed:

@match :( (a::Foo,b::Bar) ) begin
    :(($n1::$t1,)...) => (n1...,)
end # Error, non exhaustive

I also tried a simpler case with @matchast but it failed:

@matchast :( (a::Foo,) ) begin
    ($n::$t,) => n
end # Error, malformed template

@thautwarm might you have any suggestions?

Sorry for the late reply.

MLStyle supports your use case:

julia> data = :( a::Foo, b::Bar, c :: Foo, d:: Bar )
:((a::Foo, b::Bar, c::Foo, d::Bar))

@match data begin
   :($([:($a :: $b) for (a, b) in pack]...), ) => pack
end

4-element Vector{Tuple{Any, Any}}:
 (:a, :Foo)
 (:b, :Bar)
 (:c, :Foo)
 (:d, :Bar)

Iā€™d suggest using the Expr pattern because :($(pat...), ) is not-that readable.

julia> @match data begin
          Expr(:tuple, [:($a :: $b) for (a, b) in pack]...) => pack
       end
4-element Vector{Tuple{Any, Any}}:
 (:a, :Foo)
 (:b, :Bar)
 (:c, :Foo)
 (:d, :Bar)
1 Like