Coder Social home page Coder Social logo

Comments (3)

lrhn avatar lrhn commented on September 27, 2024

That's partial application of functions.

I'll admit I don't see the relation til patterns

from language.

masreplay avatar masreplay commented on September 27, 2024

Maybe not a Pattern Matching, maybe there is another way to implement it.

from language.

lrhn avatar lrhn commented on September 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.