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

consistent powerful pattern matching everywhere? #49

Closed
StefanKarpinski opened this issue Jun 15, 2011 · 6 comments
Closed

consistent powerful pattern matching everywhere? #49

StefanKarpinski opened this issue Jun 15, 2011 · 6 comments
Labels
speculative Whether the change will be implemented is speculative

Comments

@StefanKarpinski
Copy link
Member

General pattern matching a la Magpie (discussion here) used for function dispatch, destructuring, switch case dispatch, and exception handling. See the brief email thread on the subject. We could still really use some pattern matching. The hardest part would likely be integrating it with multiple dispatch.

@JeffBezanson
Copy link
Member

This is a throwaway issue. This needs a real proposal or some examples.

For functions, we would need to group patterns by type and convert the dynamic part (the part the type system doesn't model) to run-time checks:

f(x::2) = 0
f(x::3) = 1

becomes

f(x::Int32) = (x==2 ? 0 : (x==3 ? 1 : ... ))

This is really complex and makes it perhaps too easy to write overlapping or conflicting definitions. For example, you wouldn't implement +(x::Int,y::Int) = ... unless you really knew what you were doing, but it seems easier to write +(x::2, y::3) = 42. It's a silly example but you get the idea.

Another problem is that we don't have record literals, or structurally-typed records. So something like "name::String, age::Number" is not a type. As I said at one point, we could add records like this, which are basically tuples with named components. These are to keyword arguments exactly what tuples are to positional arguments, which has a certain elegance. But it just seems like too many features.

@StefanKarpinski
Copy link
Member Author

These are the reasons why I made this a v2.0 issue and a speculative one. It's really just a placeholder for keeping the possibility in mind. Maybe we have a much more limited notion of pattern matching, but using the same approach for case statements and catch blocks seems sensible. We already have limited destructuring for tuples.

@si14
Copy link

si14 commented Feb 21, 2012

+1 here :)

@friggeri
Copy link

I'd rather see something along the lines of :

f(2::Int) = 0
f(3::Int32) = 1

f(2) # -> 0
f(3::Int64) # -> no method f(3::Int64)

@JeffBezanson
Copy link
Member

Yes that syntax makes more sense.

@JeffBezanson
Copy link
Member

I don't think we need an issue to keep track of this idea.

StefanKarpinski pushed a commit that referenced this issue Feb 8, 2018
StefanKarpinski pushed a commit that referenced this issue Feb 8, 2018
* =Use abstract type, not union

* =Some abstractions
cmcaine pushed a commit to cmcaine/julia that referenced this issue Sep 24, 2020
Keno pushed a commit that referenced this issue Oct 9, 2023
More thorough detection of atsign-doc expressions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
speculative Whether the change will be implemented is speculative
Projects
None yet
Development

No branches or pull requests

4 participants