Why can Haskell handle very large numbers easily?

后端 未结 8 1924
遇见更好的自我
遇见更好的自我 2021-01-01 11:09
Hugs> 94535^445
13763208823213770506960538876615156211048901640052821530697264247739998018468419032448277029434879827074549660094560167350418780006041435009085328         


        
8条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-01 11:28

    It's a difference in design philosophy:

    • The designers of Haskell wanted to be sure that users would not be surprised by the seemingly arbitrary failure of an integer computation needing more than 32 bits.

    • The designers of Java wanted to be sure that users would not be surprised by the seemingly arbitrary performance degradation caused by doing lots of computations over integers needing more than 32 bits.

    In each language, you have to do something special to get the other kind of integer.

    There's a long, honorable history of languages supporting arbitrarily large integers by default. Two of my favorites are Icon and Smalltalk, which are both over 25 years old.

提交回复
热议问题