>>> fold [[1, 2, 3], [4, 5], [6], []] [1,2,3,4,5,6]
>>> fold $ Node (Leaf (Sum 1)) (Sum 3) (Leaf (Sum 5)) Sum {getSum = 9}Folds of unbounded structures do not terminate when the monoid's (<>) operator is strict:
>>> fold (repeat Nothing) * Hangs forever *Lazy corecursive folds of unbounded structures are fine:
>>> take 12 $ fold $ map (\i -> [i..i+2]) [0..] [0,1,2,1,2,3,2,3,4,3,4,5] >>> sum $ take 4000000 $ fold $ map (\i -> [i..i+2]) [0..] 2666668666666
>>> maximum [1..10] 10
>>> maximum [] *** Exception: Prelude.maximum: empty list
>>> maximum Nothing *** Exception: maximum: empty structureWARNING: This function is partial for possibly-empty structures like lists.
>>> minimum [1..10] 1
>>> minimum [] *** Exception: Prelude.minimum: empty list
>>> minimum Nothing *** Exception: minimum: empty structureWARNING: This function is partial for possibly-empty structures like lists.
>>> maximum [1..10] 10
>>> maximum [] *** Exception: Prelude.maximum: empty list
>>> maximum Nothing *** Exception: maximum: empty structureWARNING: This function is partial for possibly-empty structures like lists.
>>> minimum [1..10] 1
>>> minimum [] *** Exception: Prelude.minimum: empty list
>>> minimum Nothing *** Exception: minimum: empty structureWARNING: This function is partial for possibly-empty structures like lists.
>>> sum [] 0
>>> sum [42] 42
>>> sum [1..10] 55
>>> sum [4.1, 2.0, 1.7] 7.8
>>> sum [1..] * Hangs forever *
>>> product [] 1
>>> product [42] 42
>>> product [1..10] 3628800
>>> product [4.1, 2.0, 1.7] 13.939999999999998
>>> product [1..] * Hangs forever *