Page MenuHomePhabricator

Allow for currying and other partial function application
Open, Needs TriagePublicFeature

Description

Feature summary (what you would like to be able to do and where):
Create a partial function using a Z8xx

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):

  • Partial functions, which are an important concept in functional programming
  • Other built-in functions, such as map, will be made easier with this
  • A way to implement n-apply is also available here

Benefits (why should this be implemented?):
Generally helpful and a feature missing that is present in many functional programming languages

Event Timeline

Jdforrester-WMF renamed this task from Create a partial functions function to Create a mechanism by which some/all parameters to a function can be tagged as unresolved until later ("partial functions").Feb 19 2025, 5:35 PM
DVrandecic renamed this task from Create a mechanism by which some/all parameters to a function can be tagged as unresolved until later ("partial functions") to Allow for currying and other partial function application.Feb 19 2025, 6:01 PM

@cmassaro one of the tasks I mentioned during the corner

I'd like to know more about this. The composition language should already support this--at least, currying and partial functions work in our unit tests. Have you made a curried/partial function call that you expected to work, but it didn't? If so, it's a bug; if you have repro instructions, I'll be happy to take a look.

Alternatively, is this about the difficulty of creating such constructs via the frontend interface? If so, it's a larger discussion with the team :)

As far as I can tell,

Maybe https://www.wikifunctions.org/wiki/Z10249 counts as an attempt?

It seems like this combinator works. The other features (e.g. n-ary map and apply) are covered by other tasks. I recommend closing this. Any objections?

Another early attempt that might be related is https://www.wikifunctions.org/wiki/Z10111. I haven't looked at why it's not working.

I don't object to closing.

Another early attempt that might be related is https://www.wikifunctions.org/wiki/Z10111. I haven't looked at why it's not working.

I don't object to closing.

Ooh, hahaha. Z10111 is very cute but definitely won't work. I'm looking at this:

def Z10111(Z10111K1, Z10111K2):
	return lambda a: Z10111K1(Z10111K2(a))

For that to work, one could make a custom type converter that would convert Z10111K1 into a Python callable. In theory, nothing is preventing this! Someone could absolutely make a type converter that would return an object implementing __call__ (whether a class instance, a lambda, or a function). But doing that with arbitrary Z8s wouldn't work, since the type conversion logic would essentially just be the entire orchestrator.

I'll wait a bit and see if anyone pipes up before I summarily close this.

How would one go about implementing swap then? I've tried this approach a couple times without success, and looking at the implementation for the K combinator is no help, because trying to enter a literal Z8 like it has there just summons a single, non-functional field.

Hmmm, interesting. There shouldn't be any issue from the backend's perspective. It sounds like a UI problem. Do you have screenshots? If so, I would suggest filing a separate task, tagged against WikiLambda and Abstract Wikipedia Team.

How would one go about implementing swap then? I've tried this approach a couple times without success, and looking at the implementation for the K combinator is no help, because trying to enter a literal Z8 like it has there just summons a single, non-functional field.

I believe support for literal Z8s in the composition editor is the subject of T394458.

I believe support for literal Z8s in the composition editor is the subject of T394458.

There are a different scenario: A Z8 that itself returns a different callable Z8 (for example, a function accepting a binary function like add and a value like 2, and return an on-demand unary function x=>x+2). I am not sure it is in the scope of T394458: Make it nice to use function closures and possibly anonymous functions in composition editing mode.