haskell - How would I write a triangle function recursively? -


so trying write recursive function can input triangle number e.g. 5 , return answer 15. can use output correct answer:

triangle n = n * (n + 1) `div` 2 

but how recursively?

triangle 0 = 0 triangle n = n + triangle (n-1) 

but why?


Comments

Popular posts from this blog

command line - Use qwinsta in PowerShell ISE -

ruby - Net::HTTP extremely slow responses for HTTPS requests -

java - Incorrect order of records in M-M relationship in hibernate -