I'm playing around with the language to start learning and I am puzzled beyond my wits about how a recursive definition works.
For example, let's take the sequence of the Triangular numbers (TN n = sum [1..n]
)
The solution provided was:
triangularNumbers = scanl1 (+) [1..]
So far, so good.
But the solution I did come up with was:
triangularNumbers = zipWith (+) [1..] $ 0 : triangularNumbers
Which is also correct.
Now my question is: how does this translate to a lower level implementation? What happens exactly behind the scene when such a recursive definition is met?
[1..]
. – Anorthic[1..]
(well it won't look that nicely, but you can call it "naturals") ? It is using (or might use) self recursion as well and a little simpler than triangular numbers. Or even an infinite list of ones will do. Of course without using any predefined infinite lists. – Anorthic