How does Haskell evaluate this signature?












0















ggt_euklid :: Nat1 -> (Nat1 -> Nat1)



I am trying to learn partial application, I know that in this case, if the parentheses would be left out, I would get the same result, but I do not know how this signature should be evaluated.



As far as I have understood, parentheses signify that it is a function? Would that not imply that ggt_euklid takes a value Nat1 and returns a function?



Below is the complete function:



ggt_euklid x y
| x == y = x
|x>y =ggt_euklid(x-y) y
|x<y =ggt_euklid x (y-x)









share|improve this question


















  • 3





    "parentheses signify that it is a function?" No, the -> signifies that it's a function.

    – sepp2k
    Nov 21 '18 at 23:36











  • Possible duplicate of Example of deep understanding of currying

    – jberryman
    Nov 21 '18 at 23:54
















0















ggt_euklid :: Nat1 -> (Nat1 -> Nat1)



I am trying to learn partial application, I know that in this case, if the parentheses would be left out, I would get the same result, but I do not know how this signature should be evaluated.



As far as I have understood, parentheses signify that it is a function? Would that not imply that ggt_euklid takes a value Nat1 and returns a function?



Below is the complete function:



ggt_euklid x y
| x == y = x
|x>y =ggt_euklid(x-y) y
|x<y =ggt_euklid x (y-x)









share|improve this question


















  • 3





    "parentheses signify that it is a function?" No, the -> signifies that it's a function.

    – sepp2k
    Nov 21 '18 at 23:36











  • Possible duplicate of Example of deep understanding of currying

    – jberryman
    Nov 21 '18 at 23:54














0












0








0








ggt_euklid :: Nat1 -> (Nat1 -> Nat1)



I am trying to learn partial application, I know that in this case, if the parentheses would be left out, I would get the same result, but I do not know how this signature should be evaluated.



As far as I have understood, parentheses signify that it is a function? Would that not imply that ggt_euklid takes a value Nat1 and returns a function?



Below is the complete function:



ggt_euklid x y
| x == y = x
|x>y =ggt_euklid(x-y) y
|x<y =ggt_euklid x (y-x)









share|improve this question














ggt_euklid :: Nat1 -> (Nat1 -> Nat1)



I am trying to learn partial application, I know that in this case, if the parentheses would be left out, I would get the same result, but I do not know how this signature should be evaluated.



As far as I have understood, parentheses signify that it is a function? Would that not imply that ggt_euklid takes a value Nat1 and returns a function?



Below is the complete function:



ggt_euklid x y
| x == y = x
|x>y =ggt_euklid(x-y) y
|x<y =ggt_euklid x (y-x)






haskell signature currying partial-application






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 23:17









MinimaxMinimax

53312




53312








  • 3





    "parentheses signify that it is a function?" No, the -> signifies that it's a function.

    – sepp2k
    Nov 21 '18 at 23:36











  • Possible duplicate of Example of deep understanding of currying

    – jberryman
    Nov 21 '18 at 23:54














  • 3





    "parentheses signify that it is a function?" No, the -> signifies that it's a function.

    – sepp2k
    Nov 21 '18 at 23:36











  • Possible duplicate of Example of deep understanding of currying

    – jberryman
    Nov 21 '18 at 23:54








3




3





"parentheses signify that it is a function?" No, the -> signifies that it's a function.

– sepp2k
Nov 21 '18 at 23:36





"parentheses signify that it is a function?" No, the -> signifies that it's a function.

– sepp2k
Nov 21 '18 at 23:36













Possible duplicate of Example of deep understanding of currying

– jberryman
Nov 21 '18 at 23:54





Possible duplicate of Example of deep understanding of currying

– jberryman
Nov 21 '18 at 23:54












2 Answers
2






active

oldest

votes


















2















Would that not imply that ggt_euklid takes a value Nat1 and returns a
function?




No, it still imply that ggt_euklid takes one argument of type Nat1 and return a function of type Nat1->Nat1, even though, the parentheses be left out.



The Arrow -> always be right-associativity (when no parentheses), i.e.:



Nat1 -> Nat1 -> Nat1 


is equivalent to



Nat1 -> (Nat1 -> Nat1)


which is corresponding to the function application always be left-associativity. (when no parentheses) for example:



ggt_euklid 1 2


is equivalent to



(ggt_euklid 1) 2


Here



(ggt_euklid 1) ~ Nat1 -> Nat1


and



(ggt_euklid 1) 2 ~ Nat1


So, no matter whether one or two arguments apply to ggt_euklid, it always return a function of type Nat1 -> Nat1 firstly, if second argument is provided, it applies second argument to the returned function.






share|improve this answer

































    4














    You have understood the type signature correctly: it takes one argument and returns a function. That's how "multi-argument" functions in Haskell work: through currying. You can see this in action by trying this equivalent implementation:



    ggt_euklid :: Nat1 -> (Nat1 -> Nat1)
    ggt_euklid x = y -> result
    where result | x == y = x
    | x > y = ggt_euklid (x-y) y
    | x < y = ggt_euklid x (y-x)


    Here I've introduced this fairly pointless result variable as a thing to use your pattern guards on, but the idea is the same.






    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%2f53421792%2fhow-does-haskell-evaluate-this-signature%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









      2















      Would that not imply that ggt_euklid takes a value Nat1 and returns a
      function?




      No, it still imply that ggt_euklid takes one argument of type Nat1 and return a function of type Nat1->Nat1, even though, the parentheses be left out.



      The Arrow -> always be right-associativity (when no parentheses), i.e.:



      Nat1 -> Nat1 -> Nat1 


      is equivalent to



      Nat1 -> (Nat1 -> Nat1)


      which is corresponding to the function application always be left-associativity. (when no parentheses) for example:



      ggt_euklid 1 2


      is equivalent to



      (ggt_euklid 1) 2


      Here



      (ggt_euklid 1) ~ Nat1 -> Nat1


      and



      (ggt_euklid 1) 2 ~ Nat1


      So, no matter whether one or two arguments apply to ggt_euklid, it always return a function of type Nat1 -> Nat1 firstly, if second argument is provided, it applies second argument to the returned function.






      share|improve this answer






























        2















        Would that not imply that ggt_euklid takes a value Nat1 and returns a
        function?




        No, it still imply that ggt_euklid takes one argument of type Nat1 and return a function of type Nat1->Nat1, even though, the parentheses be left out.



        The Arrow -> always be right-associativity (when no parentheses), i.e.:



        Nat1 -> Nat1 -> Nat1 


        is equivalent to



        Nat1 -> (Nat1 -> Nat1)


        which is corresponding to the function application always be left-associativity. (when no parentheses) for example:



        ggt_euklid 1 2


        is equivalent to



        (ggt_euklid 1) 2


        Here



        (ggt_euklid 1) ~ Nat1 -> Nat1


        and



        (ggt_euklid 1) 2 ~ Nat1


        So, no matter whether one or two arguments apply to ggt_euklid, it always return a function of type Nat1 -> Nat1 firstly, if second argument is provided, it applies second argument to the returned function.






        share|improve this answer




























          2












          2








          2








          Would that not imply that ggt_euklid takes a value Nat1 and returns a
          function?




          No, it still imply that ggt_euklid takes one argument of type Nat1 and return a function of type Nat1->Nat1, even though, the parentheses be left out.



          The Arrow -> always be right-associativity (when no parentheses), i.e.:



          Nat1 -> Nat1 -> Nat1 


          is equivalent to



          Nat1 -> (Nat1 -> Nat1)


          which is corresponding to the function application always be left-associativity. (when no parentheses) for example:



          ggt_euklid 1 2


          is equivalent to



          (ggt_euklid 1) 2


          Here



          (ggt_euklid 1) ~ Nat1 -> Nat1


          and



          (ggt_euklid 1) 2 ~ Nat1


          So, no matter whether one or two arguments apply to ggt_euklid, it always return a function of type Nat1 -> Nat1 firstly, if second argument is provided, it applies second argument to the returned function.






          share|improve this answer
















          Would that not imply that ggt_euklid takes a value Nat1 and returns a
          function?




          No, it still imply that ggt_euklid takes one argument of type Nat1 and return a function of type Nat1->Nat1, even though, the parentheses be left out.



          The Arrow -> always be right-associativity (when no parentheses), i.e.:



          Nat1 -> Nat1 -> Nat1 


          is equivalent to



          Nat1 -> (Nat1 -> Nat1)


          which is corresponding to the function application always be left-associativity. (when no parentheses) for example:



          ggt_euklid 1 2


          is equivalent to



          (ggt_euklid 1) 2


          Here



          (ggt_euklid 1) ~ Nat1 -> Nat1


          and



          (ggt_euklid 1) 2 ~ Nat1


          So, no matter whether one or two arguments apply to ggt_euklid, it always return a function of type Nat1 -> Nat1 firstly, if second argument is provided, it applies second argument to the returned function.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 24 '18 at 15:29

























          answered Nov 22 '18 at 10:26









          assembly.jcassembly.jc

          2,0891214




          2,0891214

























              4














              You have understood the type signature correctly: it takes one argument and returns a function. That's how "multi-argument" functions in Haskell work: through currying. You can see this in action by trying this equivalent implementation:



              ggt_euklid :: Nat1 -> (Nat1 -> Nat1)
              ggt_euklid x = y -> result
              where result | x == y = x
              | x > y = ggt_euklid (x-y) y
              | x < y = ggt_euklid x (y-x)


              Here I've introduced this fairly pointless result variable as a thing to use your pattern guards on, but the idea is the same.






              share|improve this answer




























                4














                You have understood the type signature correctly: it takes one argument and returns a function. That's how "multi-argument" functions in Haskell work: through currying. You can see this in action by trying this equivalent implementation:



                ggt_euklid :: Nat1 -> (Nat1 -> Nat1)
                ggt_euklid x = y -> result
                where result | x == y = x
                | x > y = ggt_euklid (x-y) y
                | x < y = ggt_euklid x (y-x)


                Here I've introduced this fairly pointless result variable as a thing to use your pattern guards on, but the idea is the same.






                share|improve this answer


























                  4












                  4








                  4







                  You have understood the type signature correctly: it takes one argument and returns a function. That's how "multi-argument" functions in Haskell work: through currying. You can see this in action by trying this equivalent implementation:



                  ggt_euklid :: Nat1 -> (Nat1 -> Nat1)
                  ggt_euklid x = y -> result
                  where result | x == y = x
                  | x > y = ggt_euklid (x-y) y
                  | x < y = ggt_euklid x (y-x)


                  Here I've introduced this fairly pointless result variable as a thing to use your pattern guards on, but the idea is the same.






                  share|improve this answer













                  You have understood the type signature correctly: it takes one argument and returns a function. That's how "multi-argument" functions in Haskell work: through currying. You can see this in action by trying this equivalent implementation:



                  ggt_euklid :: Nat1 -> (Nat1 -> Nat1)
                  ggt_euklid x = y -> result
                  where result | x == y = x
                  | x > y = ggt_euklid (x-y) y
                  | x < y = ggt_euklid x (y-x)


                  Here I've introduced this fairly pointless result variable as a thing to use your pattern guards on, but the idea is the same.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 23:24









                  amalloyamalloy

                  59.7k5105156




                  59.7k5105156






























                      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%2f53421792%2fhow-does-haskell-evaluate-this-signature%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

                      Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

                      Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

                      A Topological Invariant for $pi_3(U(n))$