title: SMLNJ - Typcon mismatch with declared types
body: <p>I have the following issue: I am working through A. Appel's compiler in ML and I have written the following simple structure</p>
  
  <pre><code>signature Tiger_Tokens = 
  sig
      type linenum;
      type token;
      val ADD : linenum*linenum -&gt; token;
      val INT : string*linenum*linenum -&gt; token;
      val EOF : linenum*linenum -&gt; token;
  end
  
  structure Tokens :&gt; Tiger_Tokens =
      struct
          type linenum = int;
          type token = string
  
          fun ADD(i,j) = "ADD"
          fun INT(number, i, j) = "INT"
          fun EOF(i,j) = "EOF"
      end
  </code></pre>
  
  <p>Using ML-lex library I am compiling this with </p>
  
  <pre><code>type lexresult = Tokens.token
  val lineNum = ref 1;
  fun eof() = Tokens.EOF(!lineNum, !lineNum)
  
  %%
  digits=[0-9];
  %%
  \n =&gt; (!lineNum = (!lineNum) + 1; lex());
  "+" =&gt; (Tokens.ADD(yypos,yypos+1));
  {digits}+ =&gt; (Tokens.INT(yytext, yypos,yypos+1));
  </code></pre>
  
  <p>and I get the following error</p>
  
  <pre><code>tiger.lex.sml:172.8-172.33 Error: operator and operand don't agree [tycon mismatch]
    operator domain: Tokens.linenum * Tokens.linenum
    operand:         int * int
    in expression:
      Tokens.ADD (yypos,yypos + 1)
  </code></pre>
  
  <p>Now clearly I have set the type linenum to be an int. But when I call a function that expects a type linenum (which is int), and I pass an int as an argument (yypos), then it asks for Token.linenum not int. Isnt this an int since I set it as such? Or does SML see these as different types. If they do see them as different types then what is the point of a type declaration other than naming a 'special' kind of int??</p>
  
  <p>Thanks in advance.</p>