Search code examples
ocamltuareg

Ocaml: Error - this expression has type x but is used with type x


This is my error:

Error: This expression has type nfa but is here used with type nfa

What could possibly be happening to cause this? I'm using emacs tuareg, and loading evaluating files one by one. Sometimes this happens, and other times it doesn't.


Solution

  • There's a good description of this in the ocaml tutorial. What's happened is you have shadowed a type definition with a new definition:

    type nfa = int
    let f (x: nfa) = x
    
    type nfa = int
    let g (x: nfa) = x
    

    Restarting the top-level will clear out the old definitions.