sum pred list =
case predlist of
[] -> 0
h:t -> if pred h then h + sum pred t
else sum pred t
VariablesThere are many things that are much easier explained by them, and many algorithms that require mutable state to be fast. But variables are inherently imperative, explaining how instead of what, and giving little prediction of what their value may be a few lines later or after a few loop iterations. Loops generally require state to make sense, and so they are inherently imperative as well. But there are many things that are much easier explained by them, and many algorithms that require mutable state to be fast.