What does (n+1)
mean? I understand both are recursive Haskell functions and are using pattern matching.
I don't understand how it will pattern match factorial (n+1)
as well as the (n+1)
on the RHS of factorial =
.
And with the drop
function why is it drop 0 xs = xs
? And what about drop (n+1) [] = []
?
--Example 1
factorial 0 = 1
factorial (n+1) = (n+1) * factorial n
--Example 2
drop :: Int -> [a] -> [a]
drop 0 xs = xs
drop (n+1) [] = []
drop (n+1) (_:xs) = drop n xs
By the way I get errors when compiling.
- Code failed to compile
- Parse error in pattern: n + 1
Update: Thanks for pointing me to the correct terminology. I found this n+k patterns. Since n+k patterns have been removed since 2010 I also found this question on how to enable this pattern.