for
and while
), and programming without loops is almost unimaginable. However, in Haskell, there is no such syntax for loops, and the basic mechanism for looping is recursion.n
:x
, it can be defined as that number x
plus the sum of all natural numbers up to x - 1
. Let's take a closer look at what the actual execution looks like:[]
. The recursive case, however, applies the function to x
(the head of the list) and joins the result with the result of the recursive call on the remainder of the list (the tail of the list).