如何在不重复自己的情况下使该算法变得更懒惰?
(受到我对这个问题的回答的启发。) 考虑下面的代码(它应该找到小于或等于给定输入的最大元素): data TreeMap v = Leaf | Node Integer v (TreeMap v) (TreeMap v) deriving (Show, Read, Eq, Ord) closestLess :: Integer -> TreeMap v -> Maybe (Integer, v) closestLess i = precise Nothing where precise :: Maybe (Integer, v) -> TreeMap v -> Maybe (Integer, v) precise closestSoFar …