Nice TWiki > Dev > FeatureProposals > PartialApplicationSyntax (r1.4) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Dev . { Changes | Index | Search | Go }
Imported from SourceForge? RFE #672069

Background:

Many functional languages provide "curried" functions, of the form a -> b -> c, rather than the more typical (in Nice) (a,b) -> c. I think providing curried functions by default causes much confusion (and obscure error messages), so I think Nice's approach is good. But curried functions are often handy too.

Feature:

It would be good to have a compact syntax for partially applying a function. I'll suggest '_' and '...' as the symbols to use, where '_' means "omit this argument" and '...' means "omit all remaining arguments". So, for example:

String greet(String salutation, String adjective, String object) = salutation + ", " + adjective + " " + object;

test()
{
   (String, String)->String helloFun = greet("Hello", ...); //Fill first param only
   String->String helloWorldFun = helloFun(_, "world"); //Skip first param
   String message = helloWorldFun("currified"); 
   println(message);         //prints "Hello, currified world"
}

Which would be equivalent to:

test()
{
   (String, String)->String helloFun = (String adjective, String object) => greet("Hello", adjective, object));

   String->String helloWorldFun = String adjective => helloFun(adjective, "world");

   String message = helloWorldFun("currified");
   println(message);    //prints "Hello, currified world"
} 
-- BrynKeller - 13 Feb 2003

I like this idea of using '...' for curried function. There is a good chance it will get in before 1.0 . But I dont' like the '_' because it suggests that the chosen order of the parameters is wrong and in case of optional parameters the semantics are not clear. An alternative for '_' is using named parameters as in this example:

String greet(String salutation, String adjective, String object) = salutation + ", " + adjective + " " + object;
String hello(String adjective, String object) = greet("Hello", ...);
String helloWorld(String adjective) = hello(object:"world", ....);

test()
{
   String message = helloWorld("currified"); 
   println(message); 
}

-- ArjanB - 03 May 2003

That sounds like a better solution to me. We need a something for when the parameter names are not known, however:

(int,int)->int partialApplicator((int,int,int)->int theFunction)
{
  return theFunction(_,5,_);
}

A better solution might be to allow to name the sub-components of the function type:

(int,int)->int partialApplicator((int a,int b,int c)->int theFunction)
{
  return theFunction(b: 5, ...);
}

... or to allow arguments to be referred to by number (starting from 0 in this example):

(int,int)->int partialApplicator((int,int,int)->int theFunction)
{
  return theFunction(1: 5);
}

I think I prefer the naming syntax over the positional syntax.

-- BrynKeller - 05 May 2003

I like this idea of using '...' for curried function Couldn't the naming syntax apply to this also?

String hello(String adjective, String object) = greet(salutation: "Hello");
-- IsaacGouy - 14 Jan 2004

Topic PartialApplicationSyntax . { Edit | Attach | Ref-By | Printable | Diffs | r1.14 | > | r1.13 | > | r1.12 | More }
Revision r1.4 - 14 Jan 2004 - 00:13 GMT - IsaacGouy
Parents: WebHome > FeatureProposals
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.