Why can Haskell handle very large numbers easily?

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


        
8条回答
  •  星月不相逢
    2021-01-01 11:33

    Java has the notion of "Primitive Data Types" (which are the types that the processor supports) and those are different from all other Classes.

    In Haskell, Int is a type like all other types, and therefore it was easily made a member of the Num and Integral typeclasses used in (^) ("(^) :: (Num a, Integral b) => a -> b -> a"). Another member of those typeclasses is Integer, which supports integers of all sizes (as long as you have enough memory for their digits).

    In Java, you can use many "Big Numbers" libraries, but the operations for them won't use the infix operators you are used to, because those are only for "Primitive Types" in Java.

提交回复
热议问题