Comments (3)
That's partial application of functions.
I'll admit I don't see the relation til patterns
from language.
Maybe not a Pattern Matching, maybe there is another way to implement it.
from language.
The request, as I read it, is to allow a partial application of a function.
The example of a void Function(Object, StackTrace, {required void Function() refresh})
function being called with only (refresh: ...)
as argument, and that then returns a function expecting the remaining parameters, of type void Function(Object, StackTrace)
, which should presumably work just like having called the curried function ({required void Function() refresh}) => (Object _1, StackTrace _2) => originalFunction(_1, _2, refresh: refresh);
.
That's probably possible, but likely too dangerous as written.
The immediate issue is that if you forget a required parameter in a statement position, nothing happens:
foo(arg1, arg2); // forgot required arg3.
Instead of getting a warning, it just returns a partially applied function and ... discards it.
So we'd need rules to prevent that, likely saying that it's only allowed in positions where the value is not discarded (not in a void
typed context or similar).
It's not consistent. There is no way to omit only optional arguments. If you pass all the required arguments, the method should run. If you intended to get a function back with only the optional parameters left, it cannot work.
So, more likely, we need a new syntax for this. Strawman: function@(arguments)
. Horrible, hence "strawman".
Then you can do DefaultError.new@(refresh: ...)
and get a partially applied function back.
The next question becomes whether the returned function should be based on the static type or runtime type.
If you have:
int Function(int, int) f = (int a, int b, [int c = 0]) => a + b + c;
var g = f@(1); // Static type: int Function (int)
will g
have runtime type int Function(int)
or int Function(int, [int])
?
I think I'd prefer the former, making this an external operation performed at the point of the @
based on the available static types, not an operation that the function itself must perform (at this point, the function bound to f
is the only one who knows it accepts an extra optional int
, nothing else in the program has that information).
from language.
Related Issues (20)
- Infer the return type of a cycle-free arrow getter HOT 12
- Add support for extension macros and introspection HOT 1
- Add support for extension type macros and introspection HOT 3
- Macro phases example HOT 2
- Whether local variables and method parameters should be disabled and begin with an underscore HOT 1
- Disallow "identity escapes" and "escaped whitespace" in string literals. HOT 1
- Can augmentation libraries alter the `on` types for mixins/extensions? HOT 13
- Make a decision about whether or not we allow `extends` in type augmentations HOT 10
- Allow "let" instead of "final" HOT 1
- Enum name throws error after being added to map HOT 2
- How could macros and linters share logic? HOT 7
- Design the diagnostic reporting API for macros HOT 19
- Clarify the status of specification documents, integrate feature specifications into the language specification
- Clarify behavior of constructor initializer list augmentations HOT 8
- Consider requiring a keyword to open a declaration up to augmentation HOT 7
- Promoting variables of type T? to a nullable type HOT 5
- Class instance extension members HOT 5
- Record type is not a Type? HOT 2
- Allow this.{field} in the constructor parameters to refer to fields declared in a mixin. HOT 4
- Record pattern matching nullability deduction HOT 2
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 language.