[Haskell-cafe] General Advice Needed ..
Stephen Tetley
stephen.tetley at gmail.com
Thu Jan 14 11:28:48 EST 2010
Hello
Does you find this version easier to understand?
rangeProduct :: Int -> Int -> Int
rangeProduct m n = if m > n then 0
else if m == n then m
else m * rangeProduct (m+1) n
I would suspect the main point of the example is to make you think
recursively - note how rangeProduct is called from within its own
definition (on the last line of code).
Before it, there are two stopping conditions that will halt recursion
"if m > n " or "if m == n" - stopping conditions are crucial for
recursive thinking and programming - without them you will recur
endlessly and never produce an answer.
If you exam is 'on paper' - that's to say code you can have some
syntax errors because it isn't actually run - you want to be
demonstrating that you can think recursively.
Good luck
Stephen
More information about the Haskell-Cafe
mailing list