错误:定义dayshoursmins所需的RealFrac Int实例
我理解这个错误是因为我正在改变类型 - 或者沿着那些行改变 - 并且它不匹配(RealFrac a,Integral b)=> a - >湾我只是不确定如何解决它。错误发生在第2行。我尝试过使用fromIntegral,但我可能使用不正确。
dayshoursmins :: Int -> (Int, Int, Int)
dayshoursmins x = (days, hours, minutes)
where
days = floor (x / (24 * 60))
a = x - (days * (24 * 60))
hours = floor (a / 60)
b = a - (hours * 60)
minutes = b
答案 0 :(得分:2)
/
函数,如果是小数并返回Fractional
:
> :t (/)
(/) :: Fractional a => a -> a -> a
如果要使用整数除法,请改用div
函数:
dayshoursmins :: Int -> (Int, Int, Int)
dayshoursmins x = (days, hours, minutes)
where
days = x `div` (24 * 60)
a = x - (days * (24 * 60))
hours = a `div` 60
b = a - (hours * 60)
minutes = b