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