Write command-line arguments to file in SML
<p>I am trying to write the command line arguments from my <code>SML</code> program into a file, each on a separate line. If I were to run <code>sml main.sml a b c easy as 1 2 3</code> on the command line, the desired output would be to have a file with the contents:</p>

<pre><code>a
b
c
easy
as
1
2
3
</code></pre>

<p>However, I am getting the following output from <code>SML</code>:</p>

<pre><code>$ sml main.sml a b c easy as 1 2 3
val filePath = "/Users/Josue/Desktop/espi9890.txt" : string
val args = ["a","b","c","easy","as","1","2","3"] : string list
</code></pre>

<blockquote>
  <p>main.sml:4.21 Error: syntax error: inserting  EQUALOP
      /usr/local/smlnj/bin/sml: Fatal error -- Uncaught exception Compile with "syntax error" raised at
  ../compiler/Parse/main/smlfile.sml:15.24-15.46</p>
</blockquote>

<p>With this code:</p>

<pre><code>val filePath = "/Users/Josue/Desktop/espi9890.txt";
val args = CommandLine.arguments();

fun writeListToFile x =
    val str = hd x ^ "\n";
    val fd = TextIO.openAppend filePath;
    TextIO.output (fd, str);
    TextIO.closeOut fd;
    writeListToFile (tl x);
| fun writeListToFile [] =
    null;

writeListToFile args;
</code></pre>

<p>Am I missing something?</p>