title: Using Nominal Roles for Type Inference
body: <p>I have a <code>newtype</code> with a phantom type, but I'm having trouble making easy use of it.</p>
  
  <p>Consider the following example:</p>
  
  <pre><code>import Data.Coerce
  
  newtype F a b = F b
  
  myzip :: (Num b) =&gt; F a b -&gt; F a b
  myzip = (coerce (+)) myf
  
  myf :: F a b
  myf = undefined
  </code></pre>
  
  <p>GHC complains that it <code>Couldn't match representation of type ‘a0’ with that of ‘Int’</code>. Basically, the type of <code>coerce (+)</code> is <code>F a0 -&gt; F a -&gt; F a</code>, rather than the type I want, which is <code>F a -&gt; F a -&gt; F a</code>.</p>
  
  <p>Given <code>a</code>'s current role of <code>phantom</code>, this is reasonable. I'm wondering if there's a simple way to get type inference (I don't want to have to write out signatures, that's why I'm using <code>coerce</code> in the first place!) by some other method.
  In particular, I expected that if I restricted the role of the parameter <code>a</code> to nominal, then GHC would be able to tell that the only possible choice for the signature was the one I wanted. No such luck: GHC gives the same error.</p>
  
  <p>In the event it matters, in my real code the role of <code>a</code> must be at least representational, and <code>b</code> must be nominal.</p>