<div dir="ltr"><div>The discussion was back and forth with SPJ and Richard Eisenberg during the discussion about the creation of the roles machinery and Simon suggested the shape it currently has to me last night.</div><div>
<br></div><div>Having this in the class is the only way that this can lift over an &#39;unknown&#39; Functor in local scope, and permits users of a functor that is polymorphic to get access to the O(1) coercion machinery. </div>
<div><br></div><div>Without it Coercible is almost completely useless in any code that has any sort of polymorphism involved.</div><div><br></div><div>This is analogous to (&lt;$), which was added to Functor explicitly because it made an asymptotic performance difference in a large number of scenarios.<br>
</div><div><br></div><div><div>The reason this has to live in the class is analogous to how Data has to hold the at-first-glance redundant dataCast1 and dataCast2, because it is the only place the right things are known, despite them always being gcast1 and gcast2. See 7.4 in <span style="color:rgb(0,0,0);font-family:Times;font-size:medium"><a href="http://research.microsoft.com/en-us/um/people/simonpj/papers/hmap/">Scrap more boilerplate: reflection, zips, and generalised casts</a></span> for a discussion of an almost identical issue.</div>
</div><div><br></div><div>There is still some work to be done here. I definitely agree that we should add some docs to it. </div><div><br></div><div>One of the reasons why we didn&#39;t in this initial commit is because there is some of it still up in the air in terms of what is possible. The current default definition is in terms of &#39;fmap coerce&#39;, so it&#39;ll currently work with even &#39;illegal&#39; functors that don&#39;t have a representational argument, but the user doesn&#39;t see any improvement unless  One of the reasons the docs didn&#39;t go in with the first commit was that there is room for improvement. <b>If</b> we can improve some things about Coercible inference we may be able to upgrade it to actually use &#39;coerce&#39; via a default signature. </div>
<div><br></div><div>-Edward<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Sep 25, 2013 at 12:41 AM, Johan Tibell <span dir="ltr">&lt;<a href="mailto:johan.tibell@gmail.com" target="_blank">johan.tibell@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Having coerce (!) show up in such a commonly used type class is a bit<br>
alarming. Was there a libraries discussion about this? At least we<br>
should add some docs to the method.<br>
<br>
On Wed, Sep 25, 2013 at 12:37 AM,  &lt;<a href="mailto:git@git.haskell.org">git@git.haskell.org</a>&gt; wrote:<br>
&gt; Repository : ssh://<a href="http://git@git.haskell.org/base" target="_blank">git@git.haskell.org/base</a><br>
&gt;<br>
&gt; On branch  : master<br>
&gt; Link       : <a href="http://ghc.haskell.org/trac/ghc/changeset/3da4fd92e005cb9348ab2852d9268ad61ae1b347/base" target="_blank">http://ghc.haskell.org/trac/ghc/changeset/3da4fd92e005cb9348ab2852d9268ad61ae1b347/base</a><br>

&gt;<br>
&gt;&gt;---------------------------------------------------------------<br>
&gt;<br>
&gt; commit 3da4fd92e005cb9348ab2852d9268ad61ae1b347<br>
&gt; Author: Austin Seipp &lt;<a href="mailto:austin@well-typed.com">austin@well-typed.com</a>&gt;<br>
&gt; Date:   Tue Sep 24 23:20:35 2013 -0500<br>
&gt;<br>
&gt;     Add fmapCoerce to Functor class.<br>
&gt;<br>
&gt;     This allows coercions to work under functors that are not locally known.<br>
&gt;<br>
&gt;     Authored-by: Edward Kmett &lt;<a href="mailto:ekmett@gmail.com">ekmett@gmail.com</a>&gt;<br>
&gt;     Signed-off-by: Austin Seipp &lt;<a href="mailto:austin@well-typed.com">austin@well-typed.com</a>&gt;<br>
&gt;<br>
&gt;<br>
&gt;&gt;---------------------------------------------------------------<br>
&gt;<br>
&gt; 3da4fd92e005cb9348ab2852d9268ad61ae1b347<br>
&gt;  GHC/Base.lhs |    4 +++-<br>
&gt;  1 file changed, 3 insertions(+), 1 deletion(-)<br>
&gt;<br>
&gt; diff --git a/GHC/Base.lhs b/GHC/Base.lhs<br>
&gt; index d876202..55172af 100644<br>
&gt; --- a/GHC/Base.lhs<br>
&gt; +++ b/GHC/Base.lhs<br>
&gt; @@ -105,7 +105,6 @@ module GHC.Base<br>
&gt;          module GHC.Err          -- import it explicitly<br>
&gt;    )<br>
&gt;          where<br>
&gt; -<br>
&gt;  import GHC.Types<br>
&gt;  import GHC.Classes<br>
&gt;  import GHC.CString<br>
&gt; @@ -186,6 +185,9 @@ class  Functor f  where<br>
&gt;      (&lt;$)        :: a -&gt; f b -&gt; f a<br>
&gt;      (&lt;$)        =  fmap . const<br>
&gt;<br>
&gt; +    fmapCoerce :: Coercible a b =&gt; f a -&gt; f b<br>
&gt; +    fmapCoerce = fmap coerce<br>
&gt; +<br>
&gt;  {- | The &#39;Monad&#39; class defines the basic operations over a /monad/,<br>
&gt;  a concept from a branch of mathematics known as /category theory/.<br>
&gt;  From the perspective of a Haskell programmer, however, it is best to<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; ghc-commits mailing list<br>
&gt; <a href="mailto:ghc-commits@haskell.org">ghc-commits@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/ghc-commits" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-commits</a><br>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
</blockquote></div><br></div>