fork download
  1.  
  2. digitSum n
  3. | q == 0 = r
  4. | otherwise = r + digitSum q
  5. where
  6. q = div n 10
  7. r = mod n 10
  8.  
  9. printf f x = putStrLn $ show x ++ " -> " ++ show (f x)
  10.  
  11. main = mapM_ (printf digitSum) [123, 456, 789]
Success #stdin #stdout 0s 5680KB
stdin
Standard input is empty
stdout
123 -> 6
456 -> 15
789 -> 24