这是一个F#关闭。代码示例由another questionF#关闭中的懒惰评估
let isPasswordBetter (newPassword:string) (currPassword:string) =
let isLongEnough = newPassword.Length > 1
let newIsLongerThanCurrent =
(newPassword.Length > currPassword.Length)
if isLongEnough then
if newIsLongerThanCurrent then
true
else
false
else
false
let result1 = isPasswordBetter "a" "hello"
let result2 = isPasswordBetter "hellothere" "hello"
let result3 = isPasswordBetter "aaa" "hello"
启发假设一分钟即newIsLongerThanCurrent
计算量非常大。
如果我理解正确F# is lazy by default,这意味着newIsLongerThanCurrent
将在进入if than
之前总是评估,即使其评估可能不必要。因此,我应该明确地使其成为lazy。
我的理解是否正确?我宁愿避免混乱的代码,如果lazy
是没有必要推迟计算newIsLongerThanCurrent
谢谢大家的帮助,是的,F#是**不按默认值**懒.. – NoIdeaHowToFixThis