<div dir="ltr"><div><div><div><div><div>Ryan / Simon, thanks.<br><br></div>I have been working it in the way the PostRn stuff was done, but then it struck me there may be an easier way.<br><br></div>I recall there was some discussion when the PostRn/PostTc stuff went in around the closed type family solution being better, and I thought it was that the Data instances would be more easy to define.<br><br></div>And I also seem to recall that the closed type families should be able to get rid of the UndecidableInstances pragma, but I do not recall the details.<br><br></div><div>We are now able to use closed type families in GHC source, as it is supported from GHC 7.8 onwards<br></div><div><br></div>Regards<br></div> Alan<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 25, 2016 at 8:42 PM, Ryan Scott <span dir="ltr"><<a href="mailto:ryan.gl.scott@gmail.com" target="_blank">ryan.gl.scott@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>Simon is right, you cannot use a type family as an instance head. But why do you need to? Typically, if you're deriving a Data instance that involves type families, the type families would be inside another data type. A real-world example is HsBindLR [1]:<br><br> data HsBindLR idL idR<br> = FunBind {<br> ...<br> bind_fvs :: PostRn idL NameSet,<br> ...<br> } | ...<br><br></div><div>where PostRn is a type family [2]. Now, you can't simply derive Data for HsBindLR, because GHC has no way of knowing what PostRn will evaluate to! But you can use standalone deriving to get what you want:<br><br></div><div> deriving instance (Data (PostRn idL NameSet), ...) => Data (HsBindLR idL idR)<br></div><div><br></div><div>And in fact, this is what GHC does [3], using a convenient type synonyms for the long, sprawling context you need [4].<br><br></div><div>So in your example, while you can't directly create a Data instance for NameOrRdrName itself, you can quite easily create Data instances for anything that might use NameOrRdrName. Does that work for your use cases?<br></div><div><br></div>Ryan S.<br>-----<br>[1] <a href="http://git.haskell.org/ghc.git/blob/bdc555885b8898684549eca70053c9ce0ec7fa39:/compiler/hsSyn/HsBinds.hs#l111" target="_blank">http://git.haskell.org/ghc.git/blob/bdc555885b8898684549eca70053c9ce0ec7fa39:/compiler/hsSyn/HsBinds.hs#l111</a><br>[2] <a href="http://git.haskell.org/ghc.git/blob/bdc555885b8898684549eca70053c9ce0ec7fa39:/compiler/hsSyn/PlaceHolder.hs#l47" target="_blank">http://git.haskell.org/ghc.git/blob/bdc555885b8898684549eca70053c9ce0ec7fa39:/compiler/hsSyn/PlaceHolder.hs#l47</a><br>[3] <a href="http://git.haskell.org/ghc.git/blob/bdc555885b8898684549eca70053c9ce0ec7fa39:/compiler/hsSyn/HsBinds.hs#l264" target="_blank">http://git.haskell.org/ghc.git/blob/bdc555885b8898684549eca70053c9ce0ec7fa39:/compiler/hsSyn/HsBinds.hs#l264</a><br>[4] <a href="http://git.haskell.org/ghc.git/blob/bdc555885b8898684549eca70053c9ce0ec7fa39:/compiler/hsSyn/PlaceHolder.hs#l102" target="_blank">http://git.haskell.org/ghc.git/blob/bdc555885b8898684549eca70053c9ce0ec7fa39:/compiler/hsSyn/PlaceHolder.hs#l102</a><br></div>
<br>_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
<br></blockquote></div><br></div>