Why is the recursion idiom in Haskell "'n+1' and 'n'" and not "'n' and 'n-1'"?
- by rulfzid
I'm working my way through Graham Hutton's Haskell book, and in his recursion chapter, he often pattern-matches on "n+1", as in:
myReplicate1 0 _ = []
myReplicate1 (n+1) x = x : myReplicate1 n x
Why that and not the following, which (1) seems functionally identical and (2) more intuitive in terms of understanding what's happening with the recursion:
myReplicate2 0 _ = []
myReplicate2 n x = x : myReplicate2 (n-1) x
Is there something I'm missing here? Or is it just a matter of style?