title: Using ocamlyacc with sedlex
body: <p>I am trying to figure out how to use ocamlyacc with sedlex.</p>
  
  <p><code>lexer.ml</code> (using sedlex):</p>
  
  <pre><code>let rec lex (lexbuf: Sedlexing.lexbuf) =
      match%sedlex lexbuf with
      | white_space -&gt; lex lexbuf
      (* ... other lexing rules ... *)
      | _ -&gt; failwith "Unrecognized."
  </code></pre>
  
  <p>I also have an ocamlyacc file named <code>parser.mly</code>, which contains <code>parse</code> as one of the grammar rules.</p>
  
  <p>To parse a string, I used this:</p>
  
  <pre><code>let lexbuf = Sedlexing.Utf8.from_string s in
  let parsed = (Parser.parse Lexer.lex) lexbuf in
  (* ... do things ... *)
  </code></pre>
  
  <p>But during compilation, this error appears (caused by the <code>Lexer.lex</code> above):</p>
  
  <blockquote>
    <p>Error: This expression has type Sedlexing.lexbuf -> Parser.token
           but an expression was expected of type Lexing.lexbuf -> Parser.token
           Type Sedlexing.lexbuf is not compatible with type Lexing.lexbuf</p>
  </blockquote>
  
  <p>From my understanding, this error appears because ocamlyacc expects the lexer to be generated by ocamllex, and not by sedlex. So the question is: how can I use ocamlyacc with sedlex?</p>