Comments (6)
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.
from julia.
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.
from julia.
+1 here :)
from julia.
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)
from julia.
Yes that syntax makes more sense.
from julia.
I don't think we need an issue to keep track of this idea.
from julia.
Related Issues (20)
- QA with a large csv dataset HOT 2
- `cfg_simplify!` error
- `@nospecialize` on argument destructuring
- Using `include_dependency` with a non-existent file triggers precompilation at every startup HOT 2
- Can we skip writing the key into a `Dict` if we know it's already present? HOT 3
- `Undefined symbols: ___truncsfbf2` when building on macOS HOT 9
- 50x regression in copying large custom arrays. HOT 1
- ConsoleLogger not active in the REPL HOT 2
- `Base.two_mul` is constant folding incorrectly on 1.10 (but not 1.9 or 1.11) HOT 17
- "Poison" similar arrays HOT 7
- Missing package install prompt not showing before Pkg is loaded
- Prompt to add an uninstalled package on `using` only occurs if Pkg is loaded HOT 1
- Error in displaying `SubArray`s with `AbstractVector{<:CartesianIndex}` indices
- `UndefRefError` due to line completion in REPL HOT 5
- Inappropriate number of digits displayed by `show(::Complex{BigFloat}` HOT 8
- Segmentation fault in codegen upon storing ghost value to PhiC node with unboxed type HOT 1
- Explicit task pin/unpin interface HOT 3
- Deprecate `Base.@async` HOT 2
- Teach jl_create_native to emit ccallable aliases HOT 4
- Type signature abbreviation in method error sometimes hides the information you need to know why it doesn't match HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia.