title: SML: How to write two lists in files with ML
body: <p>This function writes a list of reals to a file:</p>
  
  <pre><code>fun writeReal (real, filename) = 
      let val fd = TextIO.openOut filename
          val _ = map ( fn i =&gt;  TextIO.output (fd, Real.toString i ^ "\r\n")) real
          val _ = TextIO.closeOut fd
      in () end
  </code></pre>
  
  <p>Calling the function:</p>
  
  <pre><code>writeReal ([1.0,2.0,3.0,4.0], "hello.txt")
  </code></pre>
  
  <p>writes the following to the file <em>hello.txt</em>:</p>
  
  <pre><code>1.0 
  2.0 
  3.0 
  4.0 
  </code></pre>
  
  <p>If I had two lists, one containing a list of reals, and the other a list of words, how do I read and write the two lists to the file? For example:</p>
  
  <pre><code>writeReal ([1.0,2.0,3.0,4.0], [one, two, three, four] , "hello.txt")
  </code></pre>
  
  <p>should write the following to the file <em>hello.txt</em>:</p>
  
  <pre><code>1.0 one
  2.0 two
  3.0 three
  4.0 four
  </code></pre>