Why are there RichInt or RichX in Scala?Scala Programming for AndroidScala vs. Groovy vs. ClojureAvoiding implicit def ambiguity in ScalaIs the Scala 2.8 collections library a case of “the longest suicide note in history”?Where does Scala look for implicits?Good example of implicit parameter in Scala?Scala applying implicit functions to a collectionWhy does Int not inherit/extend from Ordered[Int]Why won't Scala use implicit conversion here?Why high order implicits are ignored in some cases?

What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)

How to test if a transaction is standard without spending real money?

Can a Warlock become Neutral Good?

Today is the Center

Mathematical cryptic clues

Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)

Why was the small council so happy for Tyrion to become the Master of Coin?

What would happen to a modern skyscraper if it rains micro blackholes?

Modeling an IPv4 Address

What's the output of a record cartridge playing an out-of-speed record

What does CI-V stand for?

Is it possible to do 50 km distance without any previous training?

Can I ask the recruiters in my resume to put the reason why I am rejected?

Animated Series: Alien black spider robot crashes on Earth

Theorems that impeded progress

Can I make popcorn with any corn?

If I cast Expeditious Retreat, can I Dash as a bonus action on the same turn?

Why doesn't H₄O²⁺ exist?

Show that if two triangles built on parallel lines, with equal bases have the same perimeter only if they are congruent.

What does it mean to describe someone as a butt steak?

Is it important to consider tone, melody, and musical form while writing a song?

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

What is the offset in a seaplane's hull?

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?



Why are there RichInt or RichX in Scala?


Scala Programming for AndroidScala vs. Groovy vs. ClojureAvoiding implicit def ambiguity in ScalaIs the Scala 2.8 collections library a case of “the longest suicide note in history”?Where does Scala look for implicits?Good example of implicit parameter in Scala?Scala applying implicit functions to a collectionWhy does Int not inherit/extend from Ordered[Int]Why won't Scala use implicit conversion here?Why high order implicits are ignored in some cases?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








4















This is a simple question.



Why was not the method related to Int resided in Int?

Instead Scala bothers to put related methods into RichInt and rely on implicit conversion so as to have them work like methods of Int.



Why bother?










share|improve this question






























    4















    This is a simple question.



    Why was not the method related to Int resided in Int?

    Instead Scala bothers to put related methods into RichInt and rely on implicit conversion so as to have them work like methods of Int.



    Why bother?










    share|improve this question


























      4












      4








      4


      1






      This is a simple question.



      Why was not the method related to Int resided in Int?

      Instead Scala bothers to put related methods into RichInt and rely on implicit conversion so as to have them work like methods of Int.



      Why bother?










      share|improve this question
















      This is a simple question.



      Why was not the method related to Int resided in Int?

      Instead Scala bothers to put related methods into RichInt and rely on implicit conversion so as to have them work like methods of Int.



      Why bother?







      scala implicit






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 9 at 2:58







      WeiChing Lin

















      asked Apr 15 '15 at 15:55









      WeiChing LinWeiChing Lin

      2,18911739




      2,18911739






















          2 Answers
          2






          active

          oldest

          votes


















          5














          Scala doesn't exist in a vacuum. It was specifically designed to be hosted in an ecosystem / on a platform which was mostly designed for another language: the Java platform, the .NET platform, the ECMAScript platform, Cocoa, etc.



          This means that in some cases compromises had to be made, in order to make Scala operate seamlessly, efficiently, and with high performance with the ecosystem, libraries and language of the host platform. That's why it has null, why it has classes (it could get by with just traits, and allow traits to have constructors), why it has packages (because they can be cleanly mapped to Java packages or .NET namespaces), why it doesn't have proper tail calls, doesn't have reified generics, etc. It's even why it has curly braces, not to make it easier to integrate with Java, but to make it easier to integrate with the brains of Java developers.



          scala.Int is a fake class, it represents a native platform integer (primitive int in Java, System.Int32 in .NET, etc.) Being fake, it can't really have any methods other than the operations provided by the host environment.



          The alternative would be to have all operations in the Int class and have the compiler know the difference between which methods are native and which aren't. But that's a special case, it makes more sense to concentrate efforts on making "enrich-my-library" fast in general, so that all programmers can benefit from those optimizations instead of spending time, money and resources on optimizations that only apply to twelve or so classes.






          share|improve this answer
































            4














            The question is why not model Int richly and then optimize, for example, that it has an unboxed representation and that some operations are provided natively?



            The answer must surely be that the compiler is still not very good at these optimizations.



            scala> 42.isWhole
            res1: Boolean = true

            scala> :javap -prv -
            [snip]
            9: getstatic #26 // Field scala/runtime/RichInt$.MODULE$:Lscala/runtime/RichInt$;
            12: getstatic #31 // Field scala/Predef$.MODULE$:Lscala/Predef$;
            15: bipush 42
            17: invokevirtual #35 // Method scala/Predef$.intWrapper:(I)I
            20: invokevirtual #39 // Method scala/runtime/RichInt$.isWhole$extension:(I)Z
            23: putfield #17 // Field res1:Z
            26: return


            or under -optimize



             9: getstatic #26 // Field scala/runtime/RichInt$.MODULE$:Lscala/runtime/RichInt$;
            12: getstatic #31 // Field scala/Predef$.MODULE$:Lscala/Predef$;
            15: astore_1
            16: bipush 42
            18: invokevirtual #35 // Method scala/runtime/RichInt$.isWhole$extension:(I)Z
            21: putfield #17 // Field res0:Z
            24: return





            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%2f29655076%2fwhy-are-there-richint-or-richx-in-scala%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









              5














              Scala doesn't exist in a vacuum. It was specifically designed to be hosted in an ecosystem / on a platform which was mostly designed for another language: the Java platform, the .NET platform, the ECMAScript platform, Cocoa, etc.



              This means that in some cases compromises had to be made, in order to make Scala operate seamlessly, efficiently, and with high performance with the ecosystem, libraries and language of the host platform. That's why it has null, why it has classes (it could get by with just traits, and allow traits to have constructors), why it has packages (because they can be cleanly mapped to Java packages or .NET namespaces), why it doesn't have proper tail calls, doesn't have reified generics, etc. It's even why it has curly braces, not to make it easier to integrate with Java, but to make it easier to integrate with the brains of Java developers.



              scala.Int is a fake class, it represents a native platform integer (primitive int in Java, System.Int32 in .NET, etc.) Being fake, it can't really have any methods other than the operations provided by the host environment.



              The alternative would be to have all operations in the Int class and have the compiler know the difference between which methods are native and which aren't. But that's a special case, it makes more sense to concentrate efforts on making "enrich-my-library" fast in general, so that all programmers can benefit from those optimizations instead of spending time, money and resources on optimizations that only apply to twelve or so classes.






              share|improve this answer





























                5














                Scala doesn't exist in a vacuum. It was specifically designed to be hosted in an ecosystem / on a platform which was mostly designed for another language: the Java platform, the .NET platform, the ECMAScript platform, Cocoa, etc.



                This means that in some cases compromises had to be made, in order to make Scala operate seamlessly, efficiently, and with high performance with the ecosystem, libraries and language of the host platform. That's why it has null, why it has classes (it could get by with just traits, and allow traits to have constructors), why it has packages (because they can be cleanly mapped to Java packages or .NET namespaces), why it doesn't have proper tail calls, doesn't have reified generics, etc. It's even why it has curly braces, not to make it easier to integrate with Java, but to make it easier to integrate with the brains of Java developers.



                scala.Int is a fake class, it represents a native platform integer (primitive int in Java, System.Int32 in .NET, etc.) Being fake, it can't really have any methods other than the operations provided by the host environment.



                The alternative would be to have all operations in the Int class and have the compiler know the difference between which methods are native and which aren't. But that's a special case, it makes more sense to concentrate efforts on making "enrich-my-library" fast in general, so that all programmers can benefit from those optimizations instead of spending time, money and resources on optimizations that only apply to twelve or so classes.






                share|improve this answer



























                  5












                  5








                  5







                  Scala doesn't exist in a vacuum. It was specifically designed to be hosted in an ecosystem / on a platform which was mostly designed for another language: the Java platform, the .NET platform, the ECMAScript platform, Cocoa, etc.



                  This means that in some cases compromises had to be made, in order to make Scala operate seamlessly, efficiently, and with high performance with the ecosystem, libraries and language of the host platform. That's why it has null, why it has classes (it could get by with just traits, and allow traits to have constructors), why it has packages (because they can be cleanly mapped to Java packages or .NET namespaces), why it doesn't have proper tail calls, doesn't have reified generics, etc. It's even why it has curly braces, not to make it easier to integrate with Java, but to make it easier to integrate with the brains of Java developers.



                  scala.Int is a fake class, it represents a native platform integer (primitive int in Java, System.Int32 in .NET, etc.) Being fake, it can't really have any methods other than the operations provided by the host environment.



                  The alternative would be to have all operations in the Int class and have the compiler know the difference between which methods are native and which aren't. But that's a special case, it makes more sense to concentrate efforts on making "enrich-my-library" fast in general, so that all programmers can benefit from those optimizations instead of spending time, money and resources on optimizations that only apply to twelve or so classes.






                  share|improve this answer















                  Scala doesn't exist in a vacuum. It was specifically designed to be hosted in an ecosystem / on a platform which was mostly designed for another language: the Java platform, the .NET platform, the ECMAScript platform, Cocoa, etc.



                  This means that in some cases compromises had to be made, in order to make Scala operate seamlessly, efficiently, and with high performance with the ecosystem, libraries and language of the host platform. That's why it has null, why it has classes (it could get by with just traits, and allow traits to have constructors), why it has packages (because they can be cleanly mapped to Java packages or .NET namespaces), why it doesn't have proper tail calls, doesn't have reified generics, etc. It's even why it has curly braces, not to make it easier to integrate with Java, but to make it easier to integrate with the brains of Java developers.



                  scala.Int is a fake class, it represents a native platform integer (primitive int in Java, System.Int32 in .NET, etc.) Being fake, it can't really have any methods other than the operations provided by the host environment.



                  The alternative would be to have all operations in the Int class and have the compiler know the difference between which methods are native and which aren't. But that's a special case, it makes more sense to concentrate efforts on making "enrich-my-library" fast in general, so that all programmers can benefit from those optimizations instead of spending time, money and resources on optimizations that only apply to twelve or so classes.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 16 '15 at 6:29

























                  answered Apr 16 '15 at 6:24









                  Jörg W MittagJörg W Mittag

                  294k63359557




                  294k63359557























                      4














                      The question is why not model Int richly and then optimize, for example, that it has an unboxed representation and that some operations are provided natively?



                      The answer must surely be that the compiler is still not very good at these optimizations.



                      scala> 42.isWhole
                      res1: Boolean = true

                      scala> :javap -prv -
                      [snip]
                      9: getstatic #26 // Field scala/runtime/RichInt$.MODULE$:Lscala/runtime/RichInt$;
                      12: getstatic #31 // Field scala/Predef$.MODULE$:Lscala/Predef$;
                      15: bipush 42
                      17: invokevirtual #35 // Method scala/Predef$.intWrapper:(I)I
                      20: invokevirtual #39 // Method scala/runtime/RichInt$.isWhole$extension:(I)Z
                      23: putfield #17 // Field res1:Z
                      26: return


                      or under -optimize



                       9: getstatic #26 // Field scala/runtime/RichInt$.MODULE$:Lscala/runtime/RichInt$;
                      12: getstatic #31 // Field scala/Predef$.MODULE$:Lscala/Predef$;
                      15: astore_1
                      16: bipush 42
                      18: invokevirtual #35 // Method scala/runtime/RichInt$.isWhole$extension:(I)Z
                      21: putfield #17 // Field res0:Z
                      24: return





                      share|improve this answer



























                        4














                        The question is why not model Int richly and then optimize, for example, that it has an unboxed representation and that some operations are provided natively?



                        The answer must surely be that the compiler is still not very good at these optimizations.



                        scala> 42.isWhole
                        res1: Boolean = true

                        scala> :javap -prv -
                        [snip]
                        9: getstatic #26 // Field scala/runtime/RichInt$.MODULE$:Lscala/runtime/RichInt$;
                        12: getstatic #31 // Field scala/Predef$.MODULE$:Lscala/Predef$;
                        15: bipush 42
                        17: invokevirtual #35 // Method scala/Predef$.intWrapper:(I)I
                        20: invokevirtual #39 // Method scala/runtime/RichInt$.isWhole$extension:(I)Z
                        23: putfield #17 // Field res1:Z
                        26: return


                        or under -optimize



                         9: getstatic #26 // Field scala/runtime/RichInt$.MODULE$:Lscala/runtime/RichInt$;
                        12: getstatic #31 // Field scala/Predef$.MODULE$:Lscala/Predef$;
                        15: astore_1
                        16: bipush 42
                        18: invokevirtual #35 // Method scala/runtime/RichInt$.isWhole$extension:(I)Z
                        21: putfield #17 // Field res0:Z
                        24: return





                        share|improve this answer

























                          4












                          4








                          4







                          The question is why not model Int richly and then optimize, for example, that it has an unboxed representation and that some operations are provided natively?



                          The answer must surely be that the compiler is still not very good at these optimizations.



                          scala> 42.isWhole
                          res1: Boolean = true

                          scala> :javap -prv -
                          [snip]
                          9: getstatic #26 // Field scala/runtime/RichInt$.MODULE$:Lscala/runtime/RichInt$;
                          12: getstatic #31 // Field scala/Predef$.MODULE$:Lscala/Predef$;
                          15: bipush 42
                          17: invokevirtual #35 // Method scala/Predef$.intWrapper:(I)I
                          20: invokevirtual #39 // Method scala/runtime/RichInt$.isWhole$extension:(I)Z
                          23: putfield #17 // Field res1:Z
                          26: return


                          or under -optimize



                           9: getstatic #26 // Field scala/runtime/RichInt$.MODULE$:Lscala/runtime/RichInt$;
                          12: getstatic #31 // Field scala/Predef$.MODULE$:Lscala/Predef$;
                          15: astore_1
                          16: bipush 42
                          18: invokevirtual #35 // Method scala/runtime/RichInt$.isWhole$extension:(I)Z
                          21: putfield #17 // Field res0:Z
                          24: return





                          share|improve this answer













                          The question is why not model Int richly and then optimize, for example, that it has an unboxed representation and that some operations are provided natively?



                          The answer must surely be that the compiler is still not very good at these optimizations.



                          scala> 42.isWhole
                          res1: Boolean = true

                          scala> :javap -prv -
                          [snip]
                          9: getstatic #26 // Field scala/runtime/RichInt$.MODULE$:Lscala/runtime/RichInt$;
                          12: getstatic #31 // Field scala/Predef$.MODULE$:Lscala/Predef$;
                          15: bipush 42
                          17: invokevirtual #35 // Method scala/Predef$.intWrapper:(I)I
                          20: invokevirtual #39 // Method scala/runtime/RichInt$.isWhole$extension:(I)Z
                          23: putfield #17 // Field res1:Z
                          26: return


                          or under -optimize



                           9: getstatic #26 // Field scala/runtime/RichInt$.MODULE$:Lscala/runtime/RichInt$;
                          12: getstatic #31 // Field scala/Predef$.MODULE$:Lscala/Predef$;
                          15: astore_1
                          16: bipush 42
                          18: invokevirtual #35 // Method scala/runtime/RichInt$.isWhole$extension:(I)Z
                          21: putfield #17 // Field res0:Z
                          24: return






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Apr 15 '15 at 17:25









                          som-snyttsom-snytt

                          34.8k233101




                          34.8k233101



























                              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%2f29655076%2fwhy-are-there-richint-or-richx-in-scala%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't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                              Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                              2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived