<div dir="ltr">Non-injectivity of type families sometimes hinders type inference. Consider<div><br></div><div>&gt; Set&#39; (Set.singleton &#39;c&#39;)</div><div class="gmail_extra"><br></div><div class="gmail_extra">Naively, we only know that (Char ~ NominalArg a). Since type families are not necessarily injective, this usually means we cannot determine the type variable `a&#39; from this constraint. However, since the NominalArg instance is parametric in `a&#39;, I suspect GHC might successfully infer (Char ~ a) in this case.</div>

<div class="gmail_extra"><br></div><div class="gmail_extra">… A quick ghci test confirms that GHC does infer (Char ~ a) here. I apologize for not just experimenting in the first place, but maybe this email will save someone slightly more time than is required to read it. :P</div>

<div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 18, 2013 at 3:37 PM, Joachim Breitner <span dir="ltr">&lt;<a href="mailto:mail@joachim-breitner.de" target="_blank">mail@joachim-breitner.de</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
not sure – where would injectivity be needed?<br>
<br>
Greetings,<br>
Joachim<br>
<br>
Am Sonntag, den 18.08.2013, 15:00 -0500 schrieb Nicolas Frisby:<br>
<div class="HOEnZb"><div class="h5">&gt; Is the non-injectivity not an issue here because the type family<br>
&gt; application gets immediately simplified?<br>
&gt;<br>
&gt;<br>
&gt; On Sun, Aug 18, 2013 at 12:45 PM, Joachim Breitner<br>
&gt; &lt;<a href="mailto:mail@joachim-breitner.de">mail@joachim-breitner.de</a>&gt; wrote:<br>
&gt;         Hi,<br>
&gt;<br>
&gt;         now that roles are in HEAD, I could play around a bit with it.<br>
&gt;         They were<br>
&gt;         introduced to solve the unsoundness of newtype deriving, but<br>
&gt;         there is<br>
&gt;         also the problem of abstraction: If I define a set type based<br>
&gt;         on an ord<br>
&gt;         instance, e.g.<br>
&gt;<br>
&gt;                 data Set a = Set a -- RHS here just for demonstration<br>
&gt;<br>
&gt;         the I don’t want my users to replace a &quot;Set Int&quot; by a &quot;Set<br>
&gt;         (Down Int)&quot;,<br>
&gt;         even though the latter is a newtype of the former. This can be<br>
&gt;         prevented<br>
&gt;         by forcing the role of &quot;a&quot; to be Nominal (and not<br>
&gt;         Representational, as<br>
&gt;         it is by default). What I just noticed is that one does not<br>
&gt;         even have to<br>
&gt;         introduce new syntax for it, one can just use:<br>
&gt;<br>
&gt;                 type family NominalArg x<br>
&gt;                 type instance (NominalArg x) = x<br>
&gt;                 data Set&#39; a = Set&#39; (NominalArg a)<br>
&gt;<br>
&gt;         and get different roles; here the excerpt from --show-iface<br>
&gt;         (is there an<br>
&gt;         easier way to see role annotations):<br>
&gt;<br>
&gt;                 5b7b2f7c3883ef0d9fc7934ac56c4805<br>
&gt;                   data Set a@R<br>
&gt;                 [..]<br>
&gt;                 8e15d783d58c18b8205191ed3fd87e27<br>
&gt;                   data Set&#39; a@N<br>
&gt;<br>
&gt;         The type family does not get into the way, e.g.<br>
&gt;<br>
&gt;                 conv (Set a) = Set&#39; a<br>
&gt;<br>
&gt;         works as usual.<br>
&gt;<br>
&gt;         (I now also notice that the parser actually supports role<br>
&gt;         annotations...<br>
&gt;         but still a nice, backward-compatible trick here).<br>
&gt;<br>
&gt;         Greetings,<br>
&gt;         Joachim<br>
&gt;<br>
&gt;         --<br>
&gt;         Joachim “nomeata” Breitner<br>
&gt;           <a href="mailto:mail@joachim-breitner.de">mail@joachim-breitner.de</a> • <a href="http://www.joachim-breitner.de/" target="_blank">http://www.joachim-breitner.de/</a><br>
&gt;           Jabber: <a href="mailto:nomeata@joachim-breitner.de">nomeata@joachim-breitner.de</a>  • GPG-Key: 0x4743206C<br>
&gt;           Debian Developer: <a href="mailto:nomeata@debian.org">nomeata@debian.org</a><br>
&gt;<br>
&gt;         _______________________________________________<br>
&gt;         Glasgow-haskell-users mailing list<br>
&gt;         <a href="mailto:Glasgow-haskell-users@haskell.org">Glasgow-haskell-users@haskell.org</a><br>
&gt;         <a href="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users" target="_blank">http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Glasgow-haskell-users mailing list<br>
&gt; <a href="mailto:Glasgow-haskell-users@haskell.org">Glasgow-haskell-users@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users" target="_blank">http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</a><br>
<br>
--<br>
Joachim “nomeata” Breitner<br>
  <a href="mailto:mail@joachim-breitner.de">mail@joachim-breitner.de</a> • <a href="http://www.joachim-breitner.de/" target="_blank">http://www.joachim-breitner.de/</a><br>
  Jabber: <a href="mailto:nomeata@joachim-breitner.de">nomeata@joachim-breitner.de</a>  • GPG-Key: 0x4743206C<br>
  Debian Developer: <a href="mailto:nomeata@debian.org">nomeata@debian.org</a><br>
</div></div><br>_______________________________________________<br>
Glasgow-haskell-users mailing list<br>
<a href="mailto:Glasgow-haskell-users@haskell.org">Glasgow-haskell-users@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users" target="_blank">http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</a><br>
<br></blockquote></div><br></div></div>