Reputation: 63
I'm trying to implement my own version of the library function div
in Haskell. Here's my solution to the problem but it is not working the way I hoped and I'm not sure how else I can implement it. Any help will be highly appreciated!
div' :: Int -> Int -> Int
div' m n
| n == 0 = 0
| n > 0 = div' m (n-1) - m
Upvotes: 0
Views: 535
Reputation: 66
Are you supposed to handle the divide by 0 case? If so, then make a separate case for it.
The base case for the division algorithm should be when a < b. What should the algorithm spit out if say you have 4 / 7? The recursive case should handle when a >= b. This should get you started for defining the div function on Natural numbers.
Upvotes: 2