<div dir="ltr"><div><div><div>Just to clarify, this example is a simplification, in practice we would be applying different type for each type instance<br><br></div>e.g.<br><br>type instance XEOverLit (GhcPass 'Parsed ) = PlaceHolder<br>type instance XEOverLit (GhcPass 'Renamed ) = PlaceHolder<br>type instance XEOverLit (GhcPass 'Typechecked) = Type<br><br></div>(modelling existing PostTc)<br><br></div>Alan<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 13 November 2017 at 11:23, Alan & Kim Zimmerman <span dir="ltr"><<a href="mailto:alan.zimm@gmail.com" target="_blank">alan.zimm@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>At the moment the Trees that Grow implementation in GHC master makes use of massive constraint types to provide Data instances for the hsSyn AST.<br><br></div>I am trying to remove the need for this, and have hit a problem.<br><br></div>The example I have reduced it to is here [1]<br><br></div>The essence of the problem is <br><br>-------------------<br>data Experiment p<br> = Experiment {<br> e_ext :: (XEOverLit p),<br> e_val :: Int }<br> | XExperiment (XXOverLit p)<br>deriving instance (Data (GhcPass p)) => Data (Experiment (GhcPass p))<br><br>type family XEOverLit x<br>type family XXOverLit x<br><br>-- The following line works<br>-- type instance XEOverLit (GhcPass _) = PlaceHolder<br><br>-- The following 3 lines do noe<br>type instance XEOverLit (GhcPass 'Parsed ) = PlaceHolder<br>type instance XEOverLit (GhcPass 'Renamed ) = PlaceHolder<br>type instance XEOverLit (GhcPass 'Typechecked) = PlaceHolder<br><br>type instance XXOverLit (GhcPass _) = PlaceHolder<br>-------------------<br><div><br></div><div>Where specifying the type instance with a wild card keeps GHC happy (the XXOverLit case), but specifying for each of the three constructors for pass does not (the XEOverLit case)</div><div><br></div><div>The exact error message is</div><div><br></div><div>------------------------------</div><div>Experiment.hs:34:1: error:<br> • Could not deduce (Data (XEOverLit (GhcPass p)))<br> arising from a use of ‘k’<br> from the context: Data (GhcPass p)<br> bound by the instance declaration at Experiment.hs:34:1-69<br> • In the first argument of ‘k’, namely ‘(z Experiment `k` a1)’<br> In the expression: ((z Experiment `k` a1) `k` a2)<br> In an equation for ‘gfoldl’:<br> gfoldl k z Experiment a1 a2 = ((z Experiment `k` a1) `k` a2)<br> When typechecking the code for ‘gfoldl’<br> in a derived instance for ‘Data (Experiment (GhcPass p))’:<br> To see the code I am typechecking, use -ddump-deriv<br> |<br>34 | deriving instance (Data (GhcPass p)) => Data (Experiment (GhcPass p))<br> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<wbr>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<wbr>^^^^^^^^^<br>------------------------------<br></div><div><br>Alan</div><div><br></div><div>[1] <a href="http://lpaste.net/360017" target="_blank">http://lpaste.net/360017</a></div><div><br></div><div><br></div></div>
</blockquote></div><br></div>