Haskell currying explanation needed












4















I'm trying to understand the concept of currying and went to the Haskell documentation. However, it says that




f is the curried form of g




Yet f takes two arguments and g only one. Since currying is converting a function which takes multiple arguments to a function which takes one argument and returns another function, shouldn't 'g' be the curried function?



From the haskell documentation




Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.




f :: a -> b -> c
is the curried form of
g :: (a, b) -> c


So this does seem contradictory to me and I also don't see any of these 2 functions return a function either.










share|improve this question























  • A function that takes one k-tuple argument is sometimes said to take k arguments. This is normal terminology in mathematics.

    – molbdnilo
    Aug 22 '18 at 9:22











  • Possible duplicate of What is 'Currying'?

    – AJFarmar
    Aug 22 '18 at 10:06
















4















I'm trying to understand the concept of currying and went to the Haskell documentation. However, it says that




f is the curried form of g




Yet f takes two arguments and g only one. Since currying is converting a function which takes multiple arguments to a function which takes one argument and returns another function, shouldn't 'g' be the curried function?



From the haskell documentation




Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.




f :: a -> b -> c
is the curried form of
g :: (a, b) -> c


So this does seem contradictory to me and I also don't see any of these 2 functions return a function either.










share|improve this question























  • A function that takes one k-tuple argument is sometimes said to take k arguments. This is normal terminology in mathematics.

    – molbdnilo
    Aug 22 '18 at 9:22











  • Possible duplicate of What is 'Currying'?

    – AJFarmar
    Aug 22 '18 at 10:06














4












4








4








I'm trying to understand the concept of currying and went to the Haskell documentation. However, it says that




f is the curried form of g




Yet f takes two arguments and g only one. Since currying is converting a function which takes multiple arguments to a function which takes one argument and returns another function, shouldn't 'g' be the curried function?



From the haskell documentation




Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.




f :: a -> b -> c
is the curried form of
g :: (a, b) -> c


So this does seem contradictory to me and I also don't see any of these 2 functions return a function either.










share|improve this question














I'm trying to understand the concept of currying and went to the Haskell documentation. However, it says that




f is the curried form of g




Yet f takes two arguments and g only one. Since currying is converting a function which takes multiple arguments to a function which takes one argument and returns another function, shouldn't 'g' be the curried function?



From the haskell documentation




Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.




f :: a -> b -> c
is the curried form of
g :: (a, b) -> c


So this does seem contradictory to me and I also don't see any of these 2 functions return a function either.







haskell currying






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 22 '18 at 9:03









Wouter VandenputteWouter Vandenputte

3942415




3942415













  • A function that takes one k-tuple argument is sometimes said to take k arguments. This is normal terminology in mathematics.

    – molbdnilo
    Aug 22 '18 at 9:22











  • Possible duplicate of What is 'Currying'?

    – AJFarmar
    Aug 22 '18 at 10:06



















  • A function that takes one k-tuple argument is sometimes said to take k arguments. This is normal terminology in mathematics.

    – molbdnilo
    Aug 22 '18 at 9:22











  • Possible duplicate of What is 'Currying'?

    – AJFarmar
    Aug 22 '18 at 10:06

















A function that takes one k-tuple argument is sometimes said to take k arguments. This is normal terminology in mathematics.

– molbdnilo
Aug 22 '18 at 9:22





A function that takes one k-tuple argument is sometimes said to take k arguments. This is normal terminology in mathematics.

– molbdnilo
Aug 22 '18 at 9:22













Possible duplicate of What is 'Currying'?

– AJFarmar
Aug 22 '18 at 10:06





Possible duplicate of What is 'Currying'?

– AJFarmar
Aug 22 '18 at 10:06












2 Answers
2






active

oldest

votes


















9















Yet f takes two arguments and g only one.




No, in fact both functions take one parameter. In fact in Haskell all functions take exactly one parameter.



If you write a signature like:



f :: a ->  b -> c


then this is a less verbose form of:



f :: a -> (b -> c)


How does that work? f is a function that takes one parameter, and then returns another function that again takes a parameter.



So take for example a function add :: Int -> Int -> Int.



If we write add 5 2, we thus calculate 5 + 2. It looks like it takes two parameters, but in fact we have written (add 5) 2. We thus call the add function with 5 as parameter. This returns a function (let us call this function add5 :: Int -> Int). So this add5 function adds 5 to a number. So if we then call add5 2, then we obtain 7, since add5 returns 5 added to the parameter.



We can however construct a function (like g) that takes one parameter that is a 2-tuple, so we can use another type to pass two values as one parameter. In fact you can see g(5, 2) is actually g (5, 2): you call the function with one parameter, a 2-tuple (5, 2).



So the currying aims to transform such g function that takes one parameter (a 2-tuple) into a function f that takes again one parameter, and this will then construct a function that will take the second element of the original 2-tuple.






share|improve this answer































    5














    The type a -> b -> c is actually a -> (b -> c).



    So f doesn't take two arguments, of type a and a b and return c, it takes one argument of type a, and returns b -> c, a function from b to c.






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      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: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      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%2fstackoverflow.com%2fquestions%2f51963290%2fhaskell-currying-explanation-needed%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      9















      Yet f takes two arguments and g only one.




      No, in fact both functions take one parameter. In fact in Haskell all functions take exactly one parameter.



      If you write a signature like:



      f :: a ->  b -> c


      then this is a less verbose form of:



      f :: a -> (b -> c)


      How does that work? f is a function that takes one parameter, and then returns another function that again takes a parameter.



      So take for example a function add :: Int -> Int -> Int.



      If we write add 5 2, we thus calculate 5 + 2. It looks like it takes two parameters, but in fact we have written (add 5) 2. We thus call the add function with 5 as parameter. This returns a function (let us call this function add5 :: Int -> Int). So this add5 function adds 5 to a number. So if we then call add5 2, then we obtain 7, since add5 returns 5 added to the parameter.



      We can however construct a function (like g) that takes one parameter that is a 2-tuple, so we can use another type to pass two values as one parameter. In fact you can see g(5, 2) is actually g (5, 2): you call the function with one parameter, a 2-tuple (5, 2).



      So the currying aims to transform such g function that takes one parameter (a 2-tuple) into a function f that takes again one parameter, and this will then construct a function that will take the second element of the original 2-tuple.






      share|improve this answer




























        9















        Yet f takes two arguments and g only one.




        No, in fact both functions take one parameter. In fact in Haskell all functions take exactly one parameter.



        If you write a signature like:



        f :: a ->  b -> c


        then this is a less verbose form of:



        f :: a -> (b -> c)


        How does that work? f is a function that takes one parameter, and then returns another function that again takes a parameter.



        So take for example a function add :: Int -> Int -> Int.



        If we write add 5 2, we thus calculate 5 + 2. It looks like it takes two parameters, but in fact we have written (add 5) 2. We thus call the add function with 5 as parameter. This returns a function (let us call this function add5 :: Int -> Int). So this add5 function adds 5 to a number. So if we then call add5 2, then we obtain 7, since add5 returns 5 added to the parameter.



        We can however construct a function (like g) that takes one parameter that is a 2-tuple, so we can use another type to pass two values as one parameter. In fact you can see g(5, 2) is actually g (5, 2): you call the function with one parameter, a 2-tuple (5, 2).



        So the currying aims to transform such g function that takes one parameter (a 2-tuple) into a function f that takes again one parameter, and this will then construct a function that will take the second element of the original 2-tuple.






        share|improve this answer


























          9












          9








          9








          Yet f takes two arguments and g only one.




          No, in fact both functions take one parameter. In fact in Haskell all functions take exactly one parameter.



          If you write a signature like:



          f :: a ->  b -> c


          then this is a less verbose form of:



          f :: a -> (b -> c)


          How does that work? f is a function that takes one parameter, and then returns another function that again takes a parameter.



          So take for example a function add :: Int -> Int -> Int.



          If we write add 5 2, we thus calculate 5 + 2. It looks like it takes two parameters, but in fact we have written (add 5) 2. We thus call the add function with 5 as parameter. This returns a function (let us call this function add5 :: Int -> Int). So this add5 function adds 5 to a number. So if we then call add5 2, then we obtain 7, since add5 returns 5 added to the parameter.



          We can however construct a function (like g) that takes one parameter that is a 2-tuple, so we can use another type to pass two values as one parameter. In fact you can see g(5, 2) is actually g (5, 2): you call the function with one parameter, a 2-tuple (5, 2).



          So the currying aims to transform such g function that takes one parameter (a 2-tuple) into a function f that takes again one parameter, and this will then construct a function that will take the second element of the original 2-tuple.






          share|improve this answer














          Yet f takes two arguments and g only one.




          No, in fact both functions take one parameter. In fact in Haskell all functions take exactly one parameter.



          If you write a signature like:



          f :: a ->  b -> c


          then this is a less verbose form of:



          f :: a -> (b -> c)


          How does that work? f is a function that takes one parameter, and then returns another function that again takes a parameter.



          So take for example a function add :: Int -> Int -> Int.



          If we write add 5 2, we thus calculate 5 + 2. It looks like it takes two parameters, but in fact we have written (add 5) 2. We thus call the add function with 5 as parameter. This returns a function (let us call this function add5 :: Int -> Int). So this add5 function adds 5 to a number. So if we then call add5 2, then we obtain 7, since add5 returns 5 added to the parameter.



          We can however construct a function (like g) that takes one parameter that is a 2-tuple, so we can use another type to pass two values as one parameter. In fact you can see g(5, 2) is actually g (5, 2): you call the function with one parameter, a 2-tuple (5, 2).



          So the currying aims to transform such g function that takes one parameter (a 2-tuple) into a function f that takes again one parameter, and this will then construct a function that will take the second element of the original 2-tuple.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 22 '18 at 9:13









          Willem Van OnsemWillem Van Onsem

          151k16149238




          151k16149238

























              5














              The type a -> b -> c is actually a -> (b -> c).



              So f doesn't take two arguments, of type a and a b and return c, it takes one argument of type a, and returns b -> c, a function from b to c.






              share|improve this answer




























                5














                The type a -> b -> c is actually a -> (b -> c).



                So f doesn't take two arguments, of type a and a b and return c, it takes one argument of type a, and returns b -> c, a function from b to c.






                share|improve this answer


























                  5












                  5








                  5







                  The type a -> b -> c is actually a -> (b -> c).



                  So f doesn't take two arguments, of type a and a b and return c, it takes one argument of type a, and returns b -> c, a function from b to c.






                  share|improve this answer













                  The type a -> b -> c is actually a -> (b -> c).



                  So f doesn't take two arguments, of type a and a b and return c, it takes one argument of type a, and returns b -> c, a function from b to c.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 22 '18 at 9:09









                  Daniel MrozDaniel Mroz

                  1914




                  1914






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


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


                      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%2fstackoverflow.com%2fquestions%2f51963290%2fhaskell-currying-explanation-needed%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

                      Contact image not getting when fetch all contact list from iPhone by CNContact

                      count number of partitions of a set with n elements into k subsets

                      A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks