Phi*_*sch 0 haskell types functional-programming
以下程序应检查输入n是否可被n中的数字之和整除
module Harshad where
isHarshad :: Int -> Bool
isHarshad n = (mod n (sumDig n)) == 0)
 where 
  sumDig n 
   | (floor (n / 10) == 0) = n -- n consists of only one digit
   | otherwise = sumDig (floor (n / 10)) + floor (10*(n - floor (n / 10)))
我得到以下编译错误:*由于使用`sumDig'而导致(RealFrac Int)没有实例
即使在尝试添加各种转换后,我仍然卡住了.
完全删除小数,仅div用于整数除法:
sumDig n = if n < 10 then n -- n consists of only one digit
           else sumDig (n `div` 10) + (n `mod` 10)