A good way to avoid “sharing”?

前端 未结 1 1633
暗喜
暗喜 2020-12-31 01:17

Suppose that someone would translate this simple Python code to Haskell:

def important_astrological_calculation(di         


        
相关标签:
1条回答
  • 2020-12-31 02:16

    In this case, your pidigits list is a constant (or "constant applicative form ), and GHC will probably float it out, calculate it once, and share amongst uses. If there are no references to the CAF, it will be garbage collected.

    Now, in general, if you want something to be recalculated, turn it into a function (e.g. by adding a dummy () parameter). Examples in the linked question on CAFs: How to make a CAF not a CAF in Haskell?

    0 讨论(0)
提交回复
热议问题