Syntax for active patterns

@active Split(xs) begin
    n = length(xs)
    n%2==0 ?
        (xs[begin:Int(n/2)], xs[Int(n/2+1):end]) :
        (xs[begin:Int(floor(n/2))], xs[Int(ceil(n/2))], xs[Int(floor(n/2+1)):end])

@match [-2,-1,0,1,2] begin
    Split(left, right) => [left, empty(left), right]
    Split(left, mid, right) => [left, [mid], right]

Is this good style?

Is it possible to use [left..., mid, right...] instead of Split(left, mid, right)?


Ah, a private discussion :wink:

1 Like

In general, a pattern like [left..., mid, right...] does not have a unique match, and MLStyle does not support it.

You Split pattern looks good to me, and I can see it is useful for certain tasks.