thautwarm / MLStyle.jl

Julia functional programming infrastructures and metaprogramming facilities
https://thautwarm.github.io/MLStyle.jl/latest/
MIT License
404 stars 39 forks source link

Allow destructuring normal structs #43

Closed thautwarm closed 5 years ago

thautwarm commented 5 years ago

While Match.jl provides such functionalities, in order to support users' redefinition of the way to destructure a struct, we disabled the default way to destructure normal structs like:

struct A
  a_1
  a_2
end

@match A(1, 2) begin
    A(1, 2) => ...
end

I have an idea to solve this: register the structs to somewhere which marks all the structs that can be destructured.

struct A
  a_1
  a_2
end

@default_pattern A

@match A(1, 2) begin
    A(1, 2) => ...
end
thautwarm commented 5 years ago

Final syntax:

struct A
  a_1
  a_2
end

@as_record A

@match A(1, 2) begin
    A(1, 2) => ...
end