I was doing the 99 Problems in Haskell when I encountered a solution to Problem 19 that I did not fully understand.
The task is to write a rotate function that works
It's a specific case of what is called "n+k patterns", which is generally disliked, and will be has been removed from the language. See here for more information.
Here is a good note on n+k patterns, which quotes the following from the Haskell 98 Report (emphasis mine):
Matching an n+k pattern (where n is a variable and k is a positive integer literal) against a value v succeeds if x >= k, resulting in the binding of n to x - k, and fails otherwise. Again, the functions >= and - are overloaded, depending on the type of the pattern. The match diverges if the comparison diverges.
The interpretation of the literal k is the same as in numeric literal patterns, except that only integer literals are allowed.
So the n+1
is only matched if n
is at least 1, as you suspected. Your alternative code removes this restriction, resulting in overlapping pattern matches.