Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you match on Pair? #164

Open
jpfairbanks opened this issue Jun 25, 2023 · 1 comment
Open

How do you match on Pair? #164

jpfairbanks opened this issue Jun 25, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@jpfairbanks
Copy link

I thought this would work and the documentation doesn't have any examples of using Base.Pair as a pattern.

using MLStyle
s = 2=>3

@match s begin
  (a,b)  => a
  (a=>b) => b
end

The tuple line works fine, but then the pair line gives the following error on [d8e11817] MLStyle v0.4.17

ERROR: LoadError: PatternCompilationError(:(#= Untitled-2:7 =#), MethodError(MLStyle.MatchImpl.pattern_uncall, (Pair, MLStyle.MatchImpl.ModuleBoundedEx2tf(Main), Any[], Any[], Any[:(s::Symbol), :(v::Any)]), 0x00000000000082b5))
Stacktrace:
  [1] gen_match(val::Symbol, tbl::Expr, __source__::LineNumberNode, __module__::Module)
    @ MLStyle.MatchImpl ~/.julia/packages/MLStyle/SLOsr/src/MatchImpl.jl:712
  [2] var"@match"(__source__::LineNumberNode, __module__::Module, val::Any, tbl::Any)
    @ MLStyle.MatchImpl ~/.julia/packages/MLStyle/SLOsr/src/MatchImpl.jl:667
  [3] eval

Replacing (a=>b) with Pair(a,b) doesn't fix it.

@thautwarm thautwarm added the bug Something isn't working label Jun 28, 2023
@thautwarm
Copy link
Owner

Pair is not yet marked as a builtin pattern due to some unsolved design issues. You can try adding support in one line:

MLStyle.@as_record Pair

#= 
@match value begin
    (p1 => p2) => v  # or Pair(p1, p2) => v
end
=#
@match (1=>2) begin
    (a, b) => a + b
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants