space leak
space leak
sum [] = 0sum (x:xs) = x + sum xs
when applied to a list will build a chain of closures for theadditions and only when it reaches the end of the list will itperform the additions and free the storage. Another exampleis the function
mean l = sum l / length l
The sum function forces the entire list l to be evaluated andbuilt in the heap. None of it can be garbage collected untilthe length function has consumed it.