title: Parsing a Type using a GHC-Plugin
body: <p>I'm working on a compiler plugin that should abort compilation if a declaration doesn't have a type that given as a plugin argument.</p>
  
  <p>I think the function <code>Unify.tcMatchTy :: Type -&gt; Type -&gt; Maybe TCvSubstS</code> would do the trick. I can find one of the argument types from the inputs of the typechecker plugin, but the other comes in as a plugin argument. That is, as a <code>String</code>.</p>
  
  <p>How do I, in a typechecker plugin, get a <code>Type</code> from a <code>String</code>? I tried using <code>parseType</code> followed by calls to <code>rnHsType</code> and <code>tcLHsType</code>, which does convert a <code>String</code> into <code>Type</code>. This seems to work for simple types, but it results in this kind of error when the string contains a type variable:</p>
  
  <pre><code>Text:0:0: error: Not in scope: type variable ‘a’
  
  Text:0:0: error:
      • GHC internal error: ‘a’ is not in scope during type checking, but it passed the renamer
        tcl_env of environment: []
      • In the type ‘a -&gt; b’
  </code></pre>
  
  <p>I'm probably missing some bit (or perhaps a huge chunk) of work here, but where should I look for it?</p>
  
  <p>(Prefixing the input with a <code>forall a b.</code> caused a compiler panic)</p>