为什么Haskell可以轻松处理大数字? [英] Why can Haskell handle very large numbers easily?

查看:102
本文介绍了为什么Haskell可以轻松处理大数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 拥抱> 94535 ^ 445 
1376320882321377050696053887661515621104890164005282153069726424773999801846841903244827702943487982707454966009456016735041878000604143500908532887464920380605164932112687039059526672109818924234920844448231612532570718657160234177285377733830104834041049076609912488237219608445995072867798430614935403219495883835042862802917980856774134757390782052200512932375660858045003581611863121089979673784484701791210379500218604466721285456487387736825167702127154268533859979529612671925052419513844416493584817268143587955662039327860394141299238613042312035808541735213479394437496215520277526351425482512084759462579494878772787079101513841720202004639843443083454387175700954018825292148776647553122504118229978165851660083576570848983047255050145168802863168613110619584686348869690774233051669081248424584219383477237544209892290799448207462345346336076966775224683516220960618177284844330167142846351091001423033864986042919757795382577032341453971393897073354841924116635150129850 1199920310763542493710623070345640930776751293033837866931318439071041756195706786304971988246228049145085554675509049673689261761180946724790998279628895697533037736990175960742058931976411012109118746060408049831661774557059721928277525324952877497666820293531542260493802900405089007151694031531396682177905023061777094672344139477476738811589733444920794554059426624897515811893272009606983103501211799188450998409772705191165787198817524291902739987741132788228108661445214169585584066023250700952073494507592643939133671930831496792160665399119419838363133409989451391324218856882908886745944746055102382175908233169795044376672529292782918533687544825525731932892771209021441784257266936712356750424994012820166432027582468453325934753382207083519345119330968825989435120366791455939291141033432557082177685116652361731070207391951520508636308709489540529250497462465497729843844351095788598636126035743067399097287394281927987273737990811113331861356978683852927875754754828836606051629443063 27057220313320376280182432763977906971557137715710757099478269250731209785404487629107297262798803645379809868663503452656912571816192881412782623078761411808958183665272686617730596943579533808499348879195167683064937591552734375



为什么Haskell的计算这样的大量的和其它语言,诸如Java,不能(因此很容易)?

解决方案

Java有 BigInteger 类。



它可以将这个工具建立到语言中,但是(与许多语言一样),它倾向于将原始特征映射到CPU所支持的事物上。

另一方面,Haskell强调表现力数学符号,其中性能考虑在很大程度上是不相关的。

Hugs> 94535^445
1376320882321377050696053887661515621104890164005282153069726424773999801846841903244827702943487982707454966009456016735041878000604143500908532887464920380605164932112687039059526672109818924234920844448231612532570718657160234177285377733830104834041049076609912488237219608445995072867798430614935403219495883835042862802917980856774134757390782052200512932375660858045003581611863121089979673784484701791210379500218604466721285456487387736825167702127154268533859979529612671925052419513844416493584817268143587955662039327860394141299238613042312035808541735213479394437496215520277526351425482512084759462579494878772787079101513841720202004639843443083454387175700954018825292148776647553122504118229978165851660083576570848983047255050145168802863168613110619584686348869690774233051669081248424584219383477237544209892290799448207462345346336076966775224683516220960618177284844330167142846351091001423033864986042919757795382577032341453971393897073354841924116635150129850119992031076354249371062307034564093077675129303383786693131843907104175619570678630497198824622804914508555467550904967368926176118094672479099827962889569753303773699017596074205893197641101210911874606040804983166177455705972192827752532495287749766682029353154226049380290040508900715169403153139668217790502306177709467234413947747673881158973344492079455405942662489751581189327200960698310350121179918845099840977270519116578719881752429190273998774113278822810866144521416958558406602325070095207349450759264393913367193083149679216066539911941983836313340998945139132421885688290888674594474605510238217590823316979504437667252929278291853368754482552573193289277120902144178425726693671235675042499401282016643202758246845332593475338220708351934511933096882598943512036679145593929114103343255708217768511665236173107020739195152050863630870948954052925049746246549772984384435109578859863612603574306739909728739428192798727373799081111333186135697868385292787575475482883660605162944306327057220313320376280182432763977906971557137715710757099478269250731209785404487629107297262798803645379809868663503452656912571816192881412782623078761411808958183665272686617730596943579533808499348879195167683064937591552734375

Why can Haskell calculate such a large number, and other languages, such as Java, cannot (so easily)?

解决方案

Java has the BigInteger class.

It could have built this facility into the language, but (like many languages) it tends to make the primitive features map closely onto things that are supported by the CPU.

Haskell on the other hand emphasizes expressiveness in the style of mathematical notation, where "performance" considerations are largely irrelevant.

这篇关于为什么Haskell可以轻松处理大数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆