As a beginner to Haskell I'm having a hard time understanding why this is failing
-- this works fine of course
f :: Float
f = 1.0
f :: Num a => a
f = 1.0
-- Could not deduce (Fractional a) arising from the literal ‘1.0’
-- from the context: Num a
-- bound by the type signature for:
-- f :: forall a. Num a => a
My confusion stems from them both having instances of Num. So since Int's, Integers, Doubles, etc all have an instance of the Num typeclass, why can't I stuff any numerical value in f?
For example, negate which has a signature
negate :: Num a => a -> a will work with Int's Float's Doubles, etc.
Any insight would be greatly appreciated.
fromInteger (10 :: Integer)and 10.5 is converted tofromRational ((21 :% 2) :: Rational). Look at what the types offromIntegerandfromRationalare - Dan Robertson