Operator currying: how to convert f[a,b][c,d] to {a+c,b+d}?Prefix operator with low precedenceQuestion on...

Boundaries and Buddhism

Right indicator flash-frequency has increased and rear-right bulb is out

Can you place a web spell on a surface you cannot see?

How to make all magic-casting innate, but still rare?

How to recover a single blank shot from a film camera

Got a new frameset, don't know why I need this split ring collar?

Digital signature that is only verifiable by one specific person

Do details of my undergraduate title matter?

Is the infant mortality rate among African-American babies in Youngstown, Ohio greater than that of babies in Iran?

Why we can't jump without bending our knees?

How do I correctly reduce geometry on part of a mesh?

What is "dot" sign in •NO?

I'm yearning in grey

Is using Legacy mode is a bad thing to do?

Using roof rails to set up hammock

How to address players struggling with simple controls?

What does this Swiss black on yellow rectangular traffic sign with a symbol looking like a dart mean?

How can I maintain game balance while allowing my player to craft genuinely useful items?

Fill the maze with a wall-following Snake until it gets stuck

Build a scale without computer

How to prevent cables getting intertwined

Does anyone recognize these rockets, and their location?

Would a 7805 5v regulator drain a 9v battery?

Why do you need to heat the pan before heating the olive oil?



Operator currying: how to convert f[a,b][c,d] to {a+c,b+d}?


Prefix operator with low precedenceQuestion on operator: // NReplacing values of a functionGoing full functional (Haskell style)Is there a comprehensive list of functions with operator forms?Define multilinear operatorWriting code which generates a function to append many columns to a datasetHow to use currying to write a tail recursive function for summing factorials given a certain boundPseudo-currying in one lineDistribute operator













3












$begingroup$


This question is related to this golfing question (but I'm not interested in golfing, only in functional operator composition):



How can we convert f[a,b][c,d] to {a+c,b+d} using only operator forms and function compositions?



So far I've figured out two ways of converting f[a][b] to a+b:



Apply[Curry[Plus]] ~ Operate ~ f[a][b]
(* a + b *)

Plus @@ Apply[Curry[List]] ~ Operate ~ f[a][b]
(* a + b *)


but I'm stumped by the double-argument forms of the first problem, which interferes with currying. Do you know how to solve this?










share|improve this question











$endgroup$

















    3












    $begingroup$


    This question is related to this golfing question (but I'm not interested in golfing, only in functional operator composition):



    How can we convert f[a,b][c,d] to {a+c,b+d} using only operator forms and function compositions?



    So far I've figured out two ways of converting f[a][b] to a+b:



    Apply[Curry[Plus]] ~ Operate ~ f[a][b]
    (* a + b *)

    Plus @@ Apply[Curry[List]] ~ Operate ~ f[a][b]
    (* a + b *)


    but I'm stumped by the double-argument forms of the first problem, which interferes with currying. Do you know how to solve this?










    share|improve this question











    $endgroup$















      3












      3








      3





      $begingroup$


      This question is related to this golfing question (but I'm not interested in golfing, only in functional operator composition):



      How can we convert f[a,b][c,d] to {a+c,b+d} using only operator forms and function compositions?



      So far I've figured out two ways of converting f[a][b] to a+b:



      Apply[Curry[Plus]] ~ Operate ~ f[a][b]
      (* a + b *)

      Plus @@ Apply[Curry[List]] ~ Operate ~ f[a][b]
      (* a + b *)


      but I'm stumped by the double-argument forms of the first problem, which interferes with currying. Do you know how to solve this?










      share|improve this question











      $endgroup$




      This question is related to this golfing question (but I'm not interested in golfing, only in functional operator composition):



      How can we convert f[a,b][c,d] to {a+c,b+d} using only operator forms and function compositions?



      So far I've figured out two ways of converting f[a][b] to a+b:



      Apply[Curry[Plus]] ~ Operate ~ f[a][b]
      (* a + b *)

      Plus @@ Apply[Curry[List]] ~ Operate ~ f[a][b]
      (* a + b *)


      but I'm stumped by the double-argument forms of the first problem, which interferes with currying. Do you know how to solve this?







      core-language functional-style operators currying






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 hours ago







      Roman

















      asked 11 hours ago









      RomanRoman

      11.3k11944




      11.3k11944






















          1 Answer
          1






          active

          oldest

          votes


















          6












          $begingroup$

          Both Operate and Curry don't have access to the full expression, acting mostly on the head. This is why both of them take the depth as an optional argument, to know where to stop, since there is no other way for them to know - their modus operandi is limited to a single interation of evaluation sequence.



          What you can do is something like this:



          curry[expr_, _, 0]:=expr;

          curry[head_Symbol, combiner_, n_:2][args___] :=
          curry[head[], combiner, n][args];

          curry[head_[prev___], combiner_, n_][args___] :=
          curry[head[prev, combiner[args]], combiner, n-1]


          which then can be used as:



          Operate[Apply[curry[List, Plus]], f[a, b][c, d]]

          (* {a + b, c + d} *)


          But in a more complex case like e.g. f[a, b][c, d][e, f], you would have to manually set the depth for both Operate and curry:



          Operate[Apply[curry[List, Plus, 3]], f[a, b][c, d][e, f], 2]

          (* {a + b, c + d, e + f} *)


          Not sure how much this takes it away from the operator form paradigm you fancy, but I don't how this could be done much differently, without using some hacks (such as using the Stack), which essentially would still serve to get a hold on entire expression rather than just its left-most head.






          share|improve this answer









          $endgroup$













          • $begingroup$
            A two-argument curry, wow this is really good. Makes me wonder why Curry isn't more flexible. Needing to specify the depth, even twice, is of course a hack; but your answer already teaches me a lot. Thank you Leonid!
            $endgroup$
            – Roman
            6 hours ago










          • $begingroup$
            To get the order of the summation right, we can do Plus @@ Operate[Apply[curry[List,List]], f[a,b][c,d]] to get the desired {a+c, b+d}. For larger terms, Plus @@ Operate[Apply[curry[List,List,4]], f[a,b][c,d][e,f][g,h], 3] gives {a+c+e+g, b+d+f+h}. This usage invites the definition of listCurry[n_: 2] := curry[List, List, n] as a curried-argument-to-list-of-lists converter helper: Plus @@ Operate[Apply[listCurry[]], f[a,b][c,d]] then gives the desired {a+c, b+d}. Alternatively, make default values for the first two arguments of curry be List.
            $endgroup$
            – Roman
            5 hours ago












          • $begingroup$
            Just to give some examples of usage for Leonid's two-argument curry operator: curry[F,G][a,b,c][d,e,f] gives F[G[a,b,c], G[d,e,f]]. The function F wraps the whole expression, and each set of arguments is wrapped in G. A larger example is curry[F,G, 4][a,b][c,d][e,f][g,h] giving F[G[a,b], G[c,d], G[e,f], G[g,h]].
            $endgroup$
            – Roman
            3 hours ago












          • $begingroup$
            Leonid, I don't think it's a good idea to auto-detect the depth using Stack or similar. What if in the last example of the previous comment I wanted to curry only the first three sets of arguments? curry[F,G, 3][a,b][c,d][e,f][g,h] correctly returns F[G[a,b], G[c,d], G[e,f]][g,h] and leaves the last argument set [g,h] alone. Auto-detection of the depth wouldn't be able to handle this case.
            $endgroup$
            – Roman
            3 hours ago












          • $begingroup$
            @Roman Sure, autodetection flies in the face of operator approach, since an operator by itself knows nothing about the depth / order. You can default the combiner to List, sure.
            $endgroup$
            – Leonid Shifrin
            2 hours ago












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "387"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f200407%2foperator-currying-how-to-convert-fa-bc-d-to-ac-bd%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          6












          $begingroup$

          Both Operate and Curry don't have access to the full expression, acting mostly on the head. This is why both of them take the depth as an optional argument, to know where to stop, since there is no other way for them to know - their modus operandi is limited to a single interation of evaluation sequence.



          What you can do is something like this:



          curry[expr_, _, 0]:=expr;

          curry[head_Symbol, combiner_, n_:2][args___] :=
          curry[head[], combiner, n][args];

          curry[head_[prev___], combiner_, n_][args___] :=
          curry[head[prev, combiner[args]], combiner, n-1]


          which then can be used as:



          Operate[Apply[curry[List, Plus]], f[a, b][c, d]]

          (* {a + b, c + d} *)


          But in a more complex case like e.g. f[a, b][c, d][e, f], you would have to manually set the depth for both Operate and curry:



          Operate[Apply[curry[List, Plus, 3]], f[a, b][c, d][e, f], 2]

          (* {a + b, c + d, e + f} *)


          Not sure how much this takes it away from the operator form paradigm you fancy, but I don't how this could be done much differently, without using some hacks (such as using the Stack), which essentially would still serve to get a hold on entire expression rather than just its left-most head.






          share|improve this answer









          $endgroup$













          • $begingroup$
            A two-argument curry, wow this is really good. Makes me wonder why Curry isn't more flexible. Needing to specify the depth, even twice, is of course a hack; but your answer already teaches me a lot. Thank you Leonid!
            $endgroup$
            – Roman
            6 hours ago










          • $begingroup$
            To get the order of the summation right, we can do Plus @@ Operate[Apply[curry[List,List]], f[a,b][c,d]] to get the desired {a+c, b+d}. For larger terms, Plus @@ Operate[Apply[curry[List,List,4]], f[a,b][c,d][e,f][g,h], 3] gives {a+c+e+g, b+d+f+h}. This usage invites the definition of listCurry[n_: 2] := curry[List, List, n] as a curried-argument-to-list-of-lists converter helper: Plus @@ Operate[Apply[listCurry[]], f[a,b][c,d]] then gives the desired {a+c, b+d}. Alternatively, make default values for the first two arguments of curry be List.
            $endgroup$
            – Roman
            5 hours ago












          • $begingroup$
            Just to give some examples of usage for Leonid's two-argument curry operator: curry[F,G][a,b,c][d,e,f] gives F[G[a,b,c], G[d,e,f]]. The function F wraps the whole expression, and each set of arguments is wrapped in G. A larger example is curry[F,G, 4][a,b][c,d][e,f][g,h] giving F[G[a,b], G[c,d], G[e,f], G[g,h]].
            $endgroup$
            – Roman
            3 hours ago












          • $begingroup$
            Leonid, I don't think it's a good idea to auto-detect the depth using Stack or similar. What if in the last example of the previous comment I wanted to curry only the first three sets of arguments? curry[F,G, 3][a,b][c,d][e,f][g,h] correctly returns F[G[a,b], G[c,d], G[e,f]][g,h] and leaves the last argument set [g,h] alone. Auto-detection of the depth wouldn't be able to handle this case.
            $endgroup$
            – Roman
            3 hours ago












          • $begingroup$
            @Roman Sure, autodetection flies in the face of operator approach, since an operator by itself knows nothing about the depth / order. You can default the combiner to List, sure.
            $endgroup$
            – Leonid Shifrin
            2 hours ago
















          6












          $begingroup$

          Both Operate and Curry don't have access to the full expression, acting mostly on the head. This is why both of them take the depth as an optional argument, to know where to stop, since there is no other way for them to know - their modus operandi is limited to a single interation of evaluation sequence.



          What you can do is something like this:



          curry[expr_, _, 0]:=expr;

          curry[head_Symbol, combiner_, n_:2][args___] :=
          curry[head[], combiner, n][args];

          curry[head_[prev___], combiner_, n_][args___] :=
          curry[head[prev, combiner[args]], combiner, n-1]


          which then can be used as:



          Operate[Apply[curry[List, Plus]], f[a, b][c, d]]

          (* {a + b, c + d} *)


          But in a more complex case like e.g. f[a, b][c, d][e, f], you would have to manually set the depth for both Operate and curry:



          Operate[Apply[curry[List, Plus, 3]], f[a, b][c, d][e, f], 2]

          (* {a + b, c + d, e + f} *)


          Not sure how much this takes it away from the operator form paradigm you fancy, but I don't how this could be done much differently, without using some hacks (such as using the Stack), which essentially would still serve to get a hold on entire expression rather than just its left-most head.






          share|improve this answer









          $endgroup$













          • $begingroup$
            A two-argument curry, wow this is really good. Makes me wonder why Curry isn't more flexible. Needing to specify the depth, even twice, is of course a hack; but your answer already teaches me a lot. Thank you Leonid!
            $endgroup$
            – Roman
            6 hours ago










          • $begingroup$
            To get the order of the summation right, we can do Plus @@ Operate[Apply[curry[List,List]], f[a,b][c,d]] to get the desired {a+c, b+d}. For larger terms, Plus @@ Operate[Apply[curry[List,List,4]], f[a,b][c,d][e,f][g,h], 3] gives {a+c+e+g, b+d+f+h}. This usage invites the definition of listCurry[n_: 2] := curry[List, List, n] as a curried-argument-to-list-of-lists converter helper: Plus @@ Operate[Apply[listCurry[]], f[a,b][c,d]] then gives the desired {a+c, b+d}. Alternatively, make default values for the first two arguments of curry be List.
            $endgroup$
            – Roman
            5 hours ago












          • $begingroup$
            Just to give some examples of usage for Leonid's two-argument curry operator: curry[F,G][a,b,c][d,e,f] gives F[G[a,b,c], G[d,e,f]]. The function F wraps the whole expression, and each set of arguments is wrapped in G. A larger example is curry[F,G, 4][a,b][c,d][e,f][g,h] giving F[G[a,b], G[c,d], G[e,f], G[g,h]].
            $endgroup$
            – Roman
            3 hours ago












          • $begingroup$
            Leonid, I don't think it's a good idea to auto-detect the depth using Stack or similar. What if in the last example of the previous comment I wanted to curry only the first three sets of arguments? curry[F,G, 3][a,b][c,d][e,f][g,h] correctly returns F[G[a,b], G[c,d], G[e,f]][g,h] and leaves the last argument set [g,h] alone. Auto-detection of the depth wouldn't be able to handle this case.
            $endgroup$
            – Roman
            3 hours ago












          • $begingroup$
            @Roman Sure, autodetection flies in the face of operator approach, since an operator by itself knows nothing about the depth / order. You can default the combiner to List, sure.
            $endgroup$
            – Leonid Shifrin
            2 hours ago














          6












          6








          6





          $begingroup$

          Both Operate and Curry don't have access to the full expression, acting mostly on the head. This is why both of them take the depth as an optional argument, to know where to stop, since there is no other way for them to know - their modus operandi is limited to a single interation of evaluation sequence.



          What you can do is something like this:



          curry[expr_, _, 0]:=expr;

          curry[head_Symbol, combiner_, n_:2][args___] :=
          curry[head[], combiner, n][args];

          curry[head_[prev___], combiner_, n_][args___] :=
          curry[head[prev, combiner[args]], combiner, n-1]


          which then can be used as:



          Operate[Apply[curry[List, Plus]], f[a, b][c, d]]

          (* {a + b, c + d} *)


          But in a more complex case like e.g. f[a, b][c, d][e, f], you would have to manually set the depth for both Operate and curry:



          Operate[Apply[curry[List, Plus, 3]], f[a, b][c, d][e, f], 2]

          (* {a + b, c + d, e + f} *)


          Not sure how much this takes it away from the operator form paradigm you fancy, but I don't how this could be done much differently, without using some hacks (such as using the Stack), which essentially would still serve to get a hold on entire expression rather than just its left-most head.






          share|improve this answer









          $endgroup$



          Both Operate and Curry don't have access to the full expression, acting mostly on the head. This is why both of them take the depth as an optional argument, to know where to stop, since there is no other way for them to know - their modus operandi is limited to a single interation of evaluation sequence.



          What you can do is something like this:



          curry[expr_, _, 0]:=expr;

          curry[head_Symbol, combiner_, n_:2][args___] :=
          curry[head[], combiner, n][args];

          curry[head_[prev___], combiner_, n_][args___] :=
          curry[head[prev, combiner[args]], combiner, n-1]


          which then can be used as:



          Operate[Apply[curry[List, Plus]], f[a, b][c, d]]

          (* {a + b, c + d} *)


          But in a more complex case like e.g. f[a, b][c, d][e, f], you would have to manually set the depth for both Operate and curry:



          Operate[Apply[curry[List, Plus, 3]], f[a, b][c, d][e, f], 2]

          (* {a + b, c + d, e + f} *)


          Not sure how much this takes it away from the operator form paradigm you fancy, but I don't how this could be done much differently, without using some hacks (such as using the Stack), which essentially would still serve to get a hold on entire expression rather than just its left-most head.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 10 hours ago









          Leonid ShifrinLeonid Shifrin

          98.9k13289382




          98.9k13289382












          • $begingroup$
            A two-argument curry, wow this is really good. Makes me wonder why Curry isn't more flexible. Needing to specify the depth, even twice, is of course a hack; but your answer already teaches me a lot. Thank you Leonid!
            $endgroup$
            – Roman
            6 hours ago










          • $begingroup$
            To get the order of the summation right, we can do Plus @@ Operate[Apply[curry[List,List]], f[a,b][c,d]] to get the desired {a+c, b+d}. For larger terms, Plus @@ Operate[Apply[curry[List,List,4]], f[a,b][c,d][e,f][g,h], 3] gives {a+c+e+g, b+d+f+h}. This usage invites the definition of listCurry[n_: 2] := curry[List, List, n] as a curried-argument-to-list-of-lists converter helper: Plus @@ Operate[Apply[listCurry[]], f[a,b][c,d]] then gives the desired {a+c, b+d}. Alternatively, make default values for the first two arguments of curry be List.
            $endgroup$
            – Roman
            5 hours ago












          • $begingroup$
            Just to give some examples of usage for Leonid's two-argument curry operator: curry[F,G][a,b,c][d,e,f] gives F[G[a,b,c], G[d,e,f]]. The function F wraps the whole expression, and each set of arguments is wrapped in G. A larger example is curry[F,G, 4][a,b][c,d][e,f][g,h] giving F[G[a,b], G[c,d], G[e,f], G[g,h]].
            $endgroup$
            – Roman
            3 hours ago












          • $begingroup$
            Leonid, I don't think it's a good idea to auto-detect the depth using Stack or similar. What if in the last example of the previous comment I wanted to curry only the first three sets of arguments? curry[F,G, 3][a,b][c,d][e,f][g,h] correctly returns F[G[a,b], G[c,d], G[e,f]][g,h] and leaves the last argument set [g,h] alone. Auto-detection of the depth wouldn't be able to handle this case.
            $endgroup$
            – Roman
            3 hours ago












          • $begingroup$
            @Roman Sure, autodetection flies in the face of operator approach, since an operator by itself knows nothing about the depth / order. You can default the combiner to List, sure.
            $endgroup$
            – Leonid Shifrin
            2 hours ago


















          • $begingroup$
            A two-argument curry, wow this is really good. Makes me wonder why Curry isn't more flexible. Needing to specify the depth, even twice, is of course a hack; but your answer already teaches me a lot. Thank you Leonid!
            $endgroup$
            – Roman
            6 hours ago










          • $begingroup$
            To get the order of the summation right, we can do Plus @@ Operate[Apply[curry[List,List]], f[a,b][c,d]] to get the desired {a+c, b+d}. For larger terms, Plus @@ Operate[Apply[curry[List,List,4]], f[a,b][c,d][e,f][g,h], 3] gives {a+c+e+g, b+d+f+h}. This usage invites the definition of listCurry[n_: 2] := curry[List, List, n] as a curried-argument-to-list-of-lists converter helper: Plus @@ Operate[Apply[listCurry[]], f[a,b][c,d]] then gives the desired {a+c, b+d}. Alternatively, make default values for the first two arguments of curry be List.
            $endgroup$
            – Roman
            5 hours ago












          • $begingroup$
            Just to give some examples of usage for Leonid's two-argument curry operator: curry[F,G][a,b,c][d,e,f] gives F[G[a,b,c], G[d,e,f]]. The function F wraps the whole expression, and each set of arguments is wrapped in G. A larger example is curry[F,G, 4][a,b][c,d][e,f][g,h] giving F[G[a,b], G[c,d], G[e,f], G[g,h]].
            $endgroup$
            – Roman
            3 hours ago












          • $begingroup$
            Leonid, I don't think it's a good idea to auto-detect the depth using Stack or similar. What if in the last example of the previous comment I wanted to curry only the first three sets of arguments? curry[F,G, 3][a,b][c,d][e,f][g,h] correctly returns F[G[a,b], G[c,d], G[e,f]][g,h] and leaves the last argument set [g,h] alone. Auto-detection of the depth wouldn't be able to handle this case.
            $endgroup$
            – Roman
            3 hours ago












          • $begingroup$
            @Roman Sure, autodetection flies in the face of operator approach, since an operator by itself knows nothing about the depth / order. You can default the combiner to List, sure.
            $endgroup$
            – Leonid Shifrin
            2 hours ago
















          $begingroup$
          A two-argument curry, wow this is really good. Makes me wonder why Curry isn't more flexible. Needing to specify the depth, even twice, is of course a hack; but your answer already teaches me a lot. Thank you Leonid!
          $endgroup$
          – Roman
          6 hours ago




          $begingroup$
          A two-argument curry, wow this is really good. Makes me wonder why Curry isn't more flexible. Needing to specify the depth, even twice, is of course a hack; but your answer already teaches me a lot. Thank you Leonid!
          $endgroup$
          – Roman
          6 hours ago












          $begingroup$
          To get the order of the summation right, we can do Plus @@ Operate[Apply[curry[List,List]], f[a,b][c,d]] to get the desired {a+c, b+d}. For larger terms, Plus @@ Operate[Apply[curry[List,List,4]], f[a,b][c,d][e,f][g,h], 3] gives {a+c+e+g, b+d+f+h}. This usage invites the definition of listCurry[n_: 2] := curry[List, List, n] as a curried-argument-to-list-of-lists converter helper: Plus @@ Operate[Apply[listCurry[]], f[a,b][c,d]] then gives the desired {a+c, b+d}. Alternatively, make default values for the first two arguments of curry be List.
          $endgroup$
          – Roman
          5 hours ago






          $begingroup$
          To get the order of the summation right, we can do Plus @@ Operate[Apply[curry[List,List]], f[a,b][c,d]] to get the desired {a+c, b+d}. For larger terms, Plus @@ Operate[Apply[curry[List,List,4]], f[a,b][c,d][e,f][g,h], 3] gives {a+c+e+g, b+d+f+h}. This usage invites the definition of listCurry[n_: 2] := curry[List, List, n] as a curried-argument-to-list-of-lists converter helper: Plus @@ Operate[Apply[listCurry[]], f[a,b][c,d]] then gives the desired {a+c, b+d}. Alternatively, make default values for the first two arguments of curry be List.
          $endgroup$
          – Roman
          5 hours ago














          $begingroup$
          Just to give some examples of usage for Leonid's two-argument curry operator: curry[F,G][a,b,c][d,e,f] gives F[G[a,b,c], G[d,e,f]]. The function F wraps the whole expression, and each set of arguments is wrapped in G. A larger example is curry[F,G, 4][a,b][c,d][e,f][g,h] giving F[G[a,b], G[c,d], G[e,f], G[g,h]].
          $endgroup$
          – Roman
          3 hours ago






          $begingroup$
          Just to give some examples of usage for Leonid's two-argument curry operator: curry[F,G][a,b,c][d,e,f] gives F[G[a,b,c], G[d,e,f]]. The function F wraps the whole expression, and each set of arguments is wrapped in G. A larger example is curry[F,G, 4][a,b][c,d][e,f][g,h] giving F[G[a,b], G[c,d], G[e,f], G[g,h]].
          $endgroup$
          – Roman
          3 hours ago














          $begingroup$
          Leonid, I don't think it's a good idea to auto-detect the depth using Stack or similar. What if in the last example of the previous comment I wanted to curry only the first three sets of arguments? curry[F,G, 3][a,b][c,d][e,f][g,h] correctly returns F[G[a,b], G[c,d], G[e,f]][g,h] and leaves the last argument set [g,h] alone. Auto-detection of the depth wouldn't be able to handle this case.
          $endgroup$
          – Roman
          3 hours ago






          $begingroup$
          Leonid, I don't think it's a good idea to auto-detect the depth using Stack or similar. What if in the last example of the previous comment I wanted to curry only the first three sets of arguments? curry[F,G, 3][a,b][c,d][e,f][g,h] correctly returns F[G[a,b], G[c,d], G[e,f]][g,h] and leaves the last argument set [g,h] alone. Auto-detection of the depth wouldn't be able to handle this case.
          $endgroup$
          – Roman
          3 hours ago














          $begingroup$
          @Roman Sure, autodetection flies in the face of operator approach, since an operator by itself knows nothing about the depth / order. You can default the combiner to List, sure.
          $endgroup$
          – Leonid Shifrin
          2 hours ago




          $begingroup$
          @Roman Sure, autodetection flies in the face of operator approach, since an operator by itself knows nothing about the depth / order. You can default the combiner to List, sure.
          $endgroup$
          – Leonid Shifrin
          2 hours ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Mathematica Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f200407%2foperator-currying-how-to-convert-fa-bc-d-to-ac-bd%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

          The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

          Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...