Here is a great little Haskell snippet that will wrench you out of imperative thinking:
notimperative x = (a,b,c,d) where
(a,b) = incr x c
(c,d) = incr d a
incr i j = (i+1,j+1)
The result of evaluating notimperative 1
is (2,5,4,3)
.
A pithier, but more obvious, version is:
notimperative2 x = (a,b) where
(a,b) = (b+1,x)