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)
- the `GenericMemory` type parameters HOT 1
- Energy saving advice: Only trigger Continuous Integration manually. HOT 1
- IncrementalCompact should handle `insert_node_here!` making new basic blocks at the end of IR
- What is the recommended value of JULIA_CPU_TARGET on macOS? HOT 4
- Issue in precompiling MKL_jll HOT 2
- It is possible to construct arrays with negative first dimension HOT 4
- Improve error message when unpacking in loop misses parentheses
- Make `Core.checked_dims` public HOT 6
- Constructing a 67108864 TiB array succeeds incorrectly, corrupting memory HOT 13
- Test stdlib no longer works building into the sysimage
- REPL stdlib no longer works building into the sysimage
- Performance of `searchsorted` worse for the O(1) method HOT 7
- 1.10: regression for embedding Julia with CMake HOT 2
- Effects modeling for Unions constructed from typevars could probably be better
- `isuppercase`/`islowercase` fail on invalid characters HOT 3
- Type inference oddity reported by @code_warntype HOT 3
- Composable multithreading with OpenBLAS HOT 3
- invalid type application returns instead of throwing HOT 2
- suboptimal and unexpected subtyping
- Parser warning for `using EllipsisNotation: (..) as …`: “parentheses are not required here” HOT 1
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.