I have the following code (yyyy
and mm
defined to be type Int
):
partOne = truncate ((fromIntegral yyyy + fromIntegral mm/100) * 1.25 + 0.97)
which on being loaded into GHCi gives me an error:
No instance for (Integral Float) arising from a use of ‘truncate’
However if I directly use the following line in GHCi, it works fine:
truncate ((fromIntegral 2000 + fromIntegral 04/100) * 1.25 + 0.97)
There seems to be some problem related to the type Int
, however I am not able to figure out how.
Also, actually I don't exactly understand what (Integral Float)
means here.
For completeness's sake, the definition of the whole function is included here in case the error is caused by the whole thing instead of that single statement:
dowNumber :: Mnemonic -> PhonePad -> Date -> Float
dowNumber mn p (yyyy, mm, dd) = (partOne + partTwo) / 7 where
partOne = (truncate ((fromIntegral yyyy + (fromIntegral mm)/100) * 1.25 + 0.97))
partTwo = fromIntegral ((monthToPhone mn p mm) + dd)
Mnemonic
is just String
and PhonePad
is [(Char, Int)]
. Date
is (Int, Int, Int)
.