2 ms·
There are many instances for Fractional, but the resultant type of the (/) operator is always the same as the operands: GHCI> :i (/) class Num a => Fra
by nybble41 6y ago
There are many instances for Fractional, but the resultant type of the (/) operator is always the same as the operands:
GHCI> :i (/)
class Num a => Fractional a where
(/) :: a -> a -> a
...
-- Defined in ‘GHC.Real’
infixl 7 /
The key is that integer types aren't Fractional, so the Haskell 2010 defaulting rules[1] cause the literals to be interpreted as Double. With an appropriate default declaration GHC could have picked Ratio Integer, Complex Double, etc. instead, but without one Integer and Double are the only options and Integer wouldn't satisfy the constraints.
[1] https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-750004.3 https://www.haskell.org/onlinereport/haskell2010/haskellch4....