<div dir="ltr">Hello,<div><br></div><div>Prior to ghc-7.8, it was possible to do this:</div><div><br></div><div>> module M where</div><div>></div><div>> import qualified <span style="color:rgb(0,0,0)">Data.Vector.Generic.Base as G</span></div>
<div><span style="color:rgb(0,0,0)">> i</span><span style="color:rgb(0,0,0)">mport qualified Data.Vector.Generic.Mutable as M</span></div><div><span style="color:rgb(0,0,0)">> i</span><span style="color:rgb(0,0,0)">mport Data.Vector.Unboxed.Base -- provides MVector and Vector</span></div>
<div><span style="color:rgb(0,0,0)">></span></div><div><span style="color:rgb(0,0,0)">> n</span><span style="color:rgb(0,0,0)">ewtype Foo = Foo Int deriving (Eq, Show, Num,</span></div><div><span style="color:rgb(0,0,0)">>     </span><span style="color:rgb(0,0,0)">M.MVector MVector, G.Vector Vector, Unbox)</span></div>
<div><span style="color:rgb(0,0,0)"><br></span></div><div><span style="color:rgb(0,0,0)">M.MVector is defined as</span></div><div><span style="color:rgb(0,0,0)"><br></span></div><div><span style="color:rgb(0,0,0)">> class MVector v a where</span></div>
<div><span style="color:rgb(0,0,0)">>     basicLength :: v s a -> Int</span></div><div><font color="#000000">etc.</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">With ghc-7.8 this no longer compiles due to an unsafe coercion, as MVector s Foo and MVector s Int have different types.  The error suggests trying -XStandaloneDeriving to manually specify the context, however I don't see any way that will help in this case.</font></div>
<div><font color="#000000"><br></font></div><div><font color="#000000">For that matter, I don't see any way to fix this in the vector package either.  We might think to define</font></div><div><font color="#000000"><br>
</font></div><div><font color="#000000">> type role M.MVector nominal representational</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">but that doesn't work as both parameters to M.MVector require a nominal role (and it's probably not what we really want anyway).  Furthermore Data.Vector.Unboxed.Base.MVector (which fills in at `v` in the instance) is a data family, so we're stuck at that point also.</font></div>
<div><font color="#000000"><br></font></div><div><font color="#000000">So given this situation, is there any way to automatically derive Vector instances from newtypes?</font></div><div><font color="#000000"><br></font></div>
<div><font color="#000000">tl;dr: I would really like to be able to do:</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">> coerce (someVector :: Vector Foo) :: Vector Int</font></div><div>
<font color="#000000"><br></font></div><div><font color="#000000">am I correct that the current machinery isn't up to handling this?</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">Thanks,</font></div>
<div><font color="#000000">John</font></div></div>