title: How to solve a Digital Root using SML
body: <p>I am having trouble with writing a function that will calculate a digital root of an integer. Consider the process of taking a number 'n', adding its digits, then adding the digits
  of the number derived from it, etc., until the remaining number has only one digit.
  The final single-digit number is called the digital root of 'n'. For example, the sequence obtained from the starting number 6381 is (6381, 18, 9), so 6381 has a digital root of 9.
  My code:</p>
  <pre><code>fun digits(m:int) =
    if m &lt; 10 then
      [m]
    else 
      let
        val smallestDigit = m mod 10
        val remainingDigits = m div 10
      in
        digits remainingDigits @ [smallestDigit]
      end
     
  
  fun sum(ints) =
      if null ints then 0
      else
      (hd ints) + sum(tl ints)                              
                                
  fun digitalRoot(i:int) =
      let
         val results = sum(digits i)
      in
         results
      end      
  </code></pre>
  <p>My code only partially works. It gets 18 but I am having trouble with also getting the sum of 18.</p>