220 36505 <835cc86a-2e6c-4e17-aec7-4f16cf8b085f@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Sarfaraz Nawaz <nawazzz@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Currying or Partial Application
Date: Sat, 6 Jan 2018 06:12:20 -0800 (PST)
Lines: 244
Approved: news@gmane.org
Message-ID: <835cc86a-2e6c-4e17-aec7-4f16cf8b085f@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_8441_1957640171.1515247940469"
X-Trace: blaine.gmane.org 1515247882 4382 195.159.176.226 (6 Jan 2018 14:11:22 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 6 Jan 2018 14:11:22 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDIJVR7DRYKRBRNSYPJAKGQEHEUKZVA@isocpp.org Sat Jan 06 15:11:17 2018
Return-path: <std-proposals+bncBDIJVR7DRYKRBRNSYPJAKGQEHEUKZVA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ua0-f200.google.com ([209.85.217.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDIJVR7DRYKRBRNSYPJAKGQEHEUKZVA@isocpp.org>)
	id 1eXpBl-0000Gz-21
	for gclcip-std-proposals@m.gmane.org; Sat, 06 Jan 2018 15:11:09 +0100
Original-Received: by mail-ua0-f200.google.com with SMTP id f19sf3921411ual.5
        for <gclcip-std-proposals@m.gmane.org>; Sat, 06 Jan 2018 06:13:12 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=0uVFMixdKV1jkrzayaVFwoLqQb1dERpA6DuIO0iEr2o=;
        b=xEuvUGHtK8GK7dhBP29LefBUW1debFvIbUTJAd7hHRqe132uXAkK+x5v2YZ5y5GDQQ
         twfQGt/giVDbvO3oP0vfhxCtxCMuBCPFmyrVMkkHCza1wVaOHIqcP22RKml/wH3r1fu5
         0mNRd8ZIICwxKBxJAqTXr1qeR0QKYSNs/eTyeeA+vGKPrJ3o66tZiZzMpnoogMBDm9gF
         cI55oI6wrbjCfL4KoJvh9iVVTJiPixZgjsmpScauJVJ9wTvk6MkRMFRwZ3moOQ2U845y
         NlA7NtgtCYNguwu8etwUb1TTrQ04p6c5lrs2spqBuzQ06F+goH7cmc/yYqXdSvQK8VUF
         HNXA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=0uVFMixdKV1jkrzayaVFwoLqQb1dERpA6DuIO0iEr2o=;
        b=j67YY29XbeycnDh2oJu4Dy2PYKR/4AQIkGEog37Jjq3Pz4k5twSMePJMi9NqmBfXaT
         VwQ9fBSbbe61qhjGMmfdhv4AJzreuB2VyVep5OkwJZKkEcLEzUdRLydxwfBg/isizAaj
         prkdOMUCzPfQwxlvhTLcLzie/mXvBgS0JDL0G3qpzIKmjxe46uvdiiGOcIXc/Db5uhbc
         a6qy2sqt6muQJcaMoJe0k1gnPBmQrxcpNPCNTmHy3PFBkZvEGGk+2Iug7quu9xRskB8m
         a1NSKpqImpWQv3L/P0hYzIzmCI5GlOnDDkjiEnYYVAG3+XcyL8jq4jPSRrRBd+QapdZ9
         XaEg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=0uVFMixdKV1jkrzayaVFwoLqQb1dERpA6DuIO0iEr2o=;
        b=qyMb3Na3XaIjdPr9MW4pfCvjB8WpwBvpEbkgrOyF6wtMuxZOwCsYQlANW/fKHDywv5
         L3fGc8j/Tbef/b87/QHzDUUzxvPkWKK917W3hooGhPVA9m6DMZncs9swUXwtmp4fuFxO
         Ymgh7HiM4JkeH8U+LP2gcckNLrYKRE6S7rLJsNcgKpRh3aEJqzbiA088V5bAkkMIY+Kt
         0Mx/94Ih31ohqI0tEixo3LW8mfOozYQdZvL9FOvbVApa8sgsnYhZT3LLWwrzH50kfH76
         GeOsZUtHSOQ0o8Cn4w2tgL648z16qzebne7GAjxv/qtRGzYRF/cuSLKDID0DWZtSVtS3
         YAXQ==
X-Gm-Message-State: AKwxytdQCu69LnE3D89k7ZWJ1KmdTRv+XH6lJWjzG1W6Kb5e02OJOKlo
	SRCgUI6ekY2A7hhCUV4eG/+sAw==
X-Google-Smtp-Source: ACJfBovcNIpRHsSwos+ZcdObPQF6RJ1TOjXpGtqSYKpXx0DSwxgt+xV/FA6+9vAzrv14F3rgxNQF5w==
X-Received: by 10.31.4.69 with SMTP id 66mr2961203vke.25.1515247992144;
        Sat, 06 Jan 2018 06:13:12 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.31.48.77 with SMTP id w74ls1408907vkw.9.gmail; Sat, 06 Jan
 2018 06:12:21 -0800 (PST)
X-Received: by 10.31.194.85 with SMTP id s82mr615453vkf.1.1515247941011;
        Sat, 06 Jan 2018 06:12:21 -0800 (PST)
X-Original-Sender: nawazzz@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:36505
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/36505>

------=_Part_8441_1957640171.1515247940469
Content-Type: multipart/alternative; 
	boundary="----=_Part_8442_679882322.1515247940470"

------=_Part_8442_679882322.1515247940470
Content-Type: text/plain; charset="UTF-8"


As C++ is becoming more functional with its each release, I think we should 
also think in the direction of function partial application.

Here is one syntax (inspired from Scala):


int f(int a)(int b)(int c)  // #1
{
   return a + b + c;
}


f(10, 20, 30); // normal. full application

f(10, 20)(30); // partial application

f(10)(20, 30); // partial application

f(10)(20)(30); // partial application



Now what if we have an overload function like:


int f(int a)(std::string b)(int c)  // #2
{
  //...
}



then `f(10)` is ambiguous. In that case, we could disambiguate as:


auto f1 = f(10)(int); //Or  auto f1 = f(10) :: (int) ... stealing from 
Haskell?

f1(20, 30); // calls #1

auto f2 = f(10)(std::string); 

f2("Might work")(20); //calls #2




Thoughts?

-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/835cc86a-2e6c-4e17-aec7-4f16cf8b085f%40isocpp.org.

------=_Part_8442_679882322.1515247940470
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><br></div><div>As C++ is becoming more functional wit=
h its each release, I think we should also think in the direction of functi=
on partial application.</div><div><br></div><div>Here is one syntax (inspir=
ed from Scala):</div><br><div class=3D"prettyprint" style=3D"background-col=
or: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: sol=
id; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint">=
<div class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 f</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> a</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">)(</span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> b</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">)(</span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> c</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0</spa=
n><span style=3D"color: #800;" class=3D"styled-by-prettify">// #1</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">return</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> a </span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">+</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> b </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">+</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> c</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br><br><br>f</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span styl=
e=3D"color: #066;" class=3D"styled-by-prettify">10</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">20</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">30=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #800;" class=3D"styled-by-prettify">// normal. full application=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>f<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><sp=
an style=3D"color: #066;" class=3D"styled-by-prettify">10</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" =
class=3D"styled-by-prettify">20</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">)(</span><span style=3D"color: #066;" class=3D"styled-=
by-prettify">30</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #800;" class=3D"styled-by-prettify">// partial a=
pplication</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br><br>f</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #066;" class=3D"styled-by-prettify">10</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">)(</span><span sty=
le=3D"color: #066;" class=3D"styled-by-prettify">20</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">30</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">/=
/ </span><span style=3D"color: rgb(136, 0, 0);"><span style=3D"color: #800;=
" class=3D"styled-by-prettify">partial application</span></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br>f</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #066;" class=3D"styled-by-prettify">10</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">)(</span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">20</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">)(</span><span style=3D"color: #066;" class=3D"styled-by-pr=
ettify">30</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #800;" class=3D"styled-by-prettify">// </span><span s=
tyle=3D"color: rgb(136, 0, 0);"><span style=3D"color: #800;" class=3D"style=
d-by-prettify">partial application</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span></span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span></div></code></div><div><br><br>Now wha=
t if we have an overload function like:<br><br></div><div class=3D"prettypr=
int" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, =
187, 187); border-style: solid; border-width: 1px; word-wrap: break-word;">=
<code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> f</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> a</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)(</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">string</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> b</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">)(</span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> c</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> =C2=A0</span><span style=3D"color: #800;" class=3D"styled-by-prettify"=
>// #2</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><=
span style=3D"color: #800;" class=3D"styled-by-prettify">//...</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br><br></span></div></code></div><di=
v><span class=3D"styled-by-prettify" style=3D"font-family: monospace; backg=
round-color: rgb(250, 250, 250); color: rgb(102, 102, 0);"><br></span><span=
 class=3D"styled-by-prettify" style=3D"font-family: monospace; background-c=
olor: rgb(250, 250, 250); color: rgb(0, 0, 0);"><br>then `f(10)` is ambiguo=
us. In that case, we could disambiguate as:</span></div><div><span class=3D=
"styled-by-prettify" style=3D"font-family: monospace; background-color: rgb=
(250, 250, 250); color: rgb(0, 0, 0);"><br></span></div><div><span class=3D=
"styled-by-prettify" style=3D"font-family: monospace; background-color: rgb=
(250, 250, 250);"><div class=3D"prettyprint" style=3D"background-color: rgb=
(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bor=
der-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint" style=
=3D""><div class=3D"subprettyprint" style=3D""><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> f1 </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> f</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</=
span><span style=3D"color: #066;" class=3D"styled-by-prettify">10</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">)(</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">//Or =C2=A0auto f1 =3D f(10) :: (int) ... stealing =
from Haskell?</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br><br>f1</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><font color=3D"#006666"><span style=3D"color: #066;" class=3D"st=
yled-by-prettify">20</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">30</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #800;" class=3D"styled-by-prettify">// calls #1</span></font><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> f2 </span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> f</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #066;" class=3D"styled-b=
y-prettify">10</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">)(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">string</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> <br><br>f2</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #080;" class=3D"styled-by-prettify">&quot;Might work&quot;</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">)(</span><font color=3D"#=
006666"><span style=3D"color: #066;" class=3D"styled-by-prettify">20</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #800;" class=3D"styled-by-prettify">//calls #2</span></font><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br><br><br></span></div></=
code></div><br><br>Thoughts?<br><br></span></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/835cc86a-2e6c-4e17-aec7-4f16cf8b085f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/835cc86a-2e6c-4e17-aec7-4f16cf8b085f=
%40isocpp.org</a>.<br />

------=_Part_8442_679882322.1515247940470--

------=_Part_8441_1957640171.1515247940469--

.
