Divide Int by Int and return Int

I need a function that takes two Int ( a and b ) and returns A/B as Int . I am sure that A/B will always be an integer.

Here is my solution:

 myDiv :: Int -> Int -> Int myDiv ab = let x = fromIntegral a y = fromIntegral b in truncate (x / y) 

But you want to find a simpler solution. Something like that:

 myDiv :: Int -> Int -> Int myDiv ab = a / b 

How can I split Int by Int and get Int?

+74
int haskell
Dec 05 '10 at 13:30
source share
2 answers

Why not just use quot ?

 quot ab 

is an integer of integers a and b truncated to zero.

+134
Dec 05 '10 at
source share

Here is what I did to make my own:

 quot' ab | a<b = 0 -- base case | otherwise = 1 + quot' ab b 
+1
Feb 09 '18 at 21:59
source share



All Articles