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

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -