Rumah >pembangunan bahagian belakang >Tutorial Python >为什么函数式语言中all odd [] 得到True?
<code class="language-scala"><span class="nc">List</span><span class="o">().</span><span class="n">forall</span><span class="o">(</span><span class="n">f</span><span class="o">)</span>
</code>
我觉得其他答案里提到的 Vacuous truth 已经很简单地回答这个问题<code class="language-haskell"><span class="kt">True</span> <span class="o">&&</span> <span class="n">x</span> <span class="c1">-- => x</span>
<span class="nf">x</span> <span class="o">&&</span> <span class="kt">True</span> <span class="c1">-- => x</span>
</code>
「所有元素都是奇數」等價於「沒有一個元素不是奇數」。<code class="language-text">for x in xs
if x is not odd
return false
return true
</code>
如果你自己用递归写判断一个数组是否为奇的方法