In ghci I get the following:
λ> -1 `div` 2
0
However:
λ> map (`div` 2) [-1]
[-1]
The problem arose when I was using a function divPair
:
divPair :: (Int, Int) -> Int -> (Int, Int)
divPair (a, b) n = (a `div` n, b `div` n)
λ> divPair (-1, -2) 2
(-1,-1)
which was really a surprise to me as I expected it to produce (0, -1)
.
What happened here? I suppose I didn't really understand something about div
in Haskell.