fork download
  1.  
  2. digitSum n = let { q = div n 10 ; r = mod n 10 } in
  3. if q == 0 then r else r + digitSum q
  4.  
  5. printf f x = putStrLn $ show x ++ " -> " ++ show (f x)
  6.  
  7. main = mapM_ (printf digitSum) [123, 456, 789]
Success #stdin #stdout 0s 5680KB
stdin
Standard input is empty
stdout
123 -> 6
456 -> 15
789 -> 24