运营商的时间成本

运营商的时间成本

本文介绍了Haskell`seq`运营商的时间成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表示

这太糟糕了Haskell不错,但这是否意味着在

    c> x ,但是由于已经评估过该值,因此所有对 x 的引用都将更新为不​​再指向未评估版本的 x ,而是指向评估版本。因此,尽管 seq 评估并放弃了 x ,但其值为 x ,因此不会重复评估。


This FAQ says that

That's awfully nice of Haskell, but does it mean that in

x `seq` f x

the cost of evaluating x will be paid twice ("discard the result")?

解决方案

The seq function will discard the value of x, but since the value has been evaluated, all references to x are "updated" to no longer point to the unevaluated version of x, but to instead point to the evaluated version. So, even though seq evaluates and discards x, the value has been evaluated for other users of x as well, leading to no repeated evaluations.

这篇关于Haskell`seq`运营商的时间成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 15:18