-
Notifications
You must be signed in to change notification settings - Fork 6
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
Support parametric types #26
Comments
I think you've structured your pattern incorrectly.
julia> @match Val(2) begin
Val{2}() => "hi"
Val{3}() => "bye"
end
"hi"
julia> @match Val(3) begin
Val{2}() => "hi"
Val{3}() => "bye"
end
"bye" But you're right that it still doesn't seem to work with variables in the type parameter: julia> @match Val(2) begin
Val{2}() => "hi"
Val{x}() => "bye"
end
ERROR: UndefVarError: x not defined EDIT: Okay never mind, I didn't realize, apparently you can also just put the type there, and it will match on that? In which case, you're right the example you posted is broken. julia> @match 2 begin
Int => "hi"
x => "bye"
end
"hi" But i'm not sure if Sooo anyway, you're right that type params aren't supported, but i'm still not sure whether we intend to support the syntax as you've written it? |
More brokenness: julia> @match Val(2) begin
_::Val{2} => "hi"
_::Val{x} => "bye"
end
"hi"
julia> @match Val(3) begin
_::Val{2} => "hi"
_::Val{x} => "bye"
end
ERROR: UndefVarError: x not defined |
@rai-nhdaly FYI, you cannot use a type as a pattern: @match 2 begin
Int => "hi"
x => 'bye"
end binds 2 to the variable That said, Rematch should allow type variables to be bound in @match Val(3) begin
_::Val{x} where x => @assert x == 3
end and @match [1,2,3] begin
_::Vector{T} where T => @assert T == Int
end If you write this now you get: julia> @match [1,2,3] begin
_::Vector{T} where T => @assert T == Int
end
ERROR: UndefVarError: T not defined |
Rematch can't handle pattern matching on parametric types:
The text was updated successfully, but these errors were encountered: