<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><base href="x-msg://1366/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Simon,</div><div><br></div><div>I've been encouraging the type family approach. See <a href="https://phabricator.haskell.org/D157">https://phabricator.haskell.org/D157</a></div><div><br></div><div>Thanks,</div><div>Richard</div><br><div><div>On Aug 15, 2014, at 11:17 AM, Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div lang="EN-GB" link="blue" vlink="purple" style="font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="WordSection1" style="page: WordSection1; "><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Eek.  Glancing at this I see that every single data type has an extra type parameter.  To me this feels like a sledgehammer to crack a nut.  What is wrong with the type-function approach?<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Simon<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span></div><div style="border-style: none none none solid; border-left-width: 1.5pt; border-left-color: blue; padding: 0cm 0cm 0cm 4pt; "><div><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0cm 0cm; "><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><b><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; ">From:</span></b><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; "><span class="Apple-converted-space"> </span>Alan & Kim Zimmerman [mailto:alan.zimm@<a href="http://gmail.com" style="color: purple; text-decoration: underline; ">gmail.com</a>]<span class="Apple-converted-space"> </span><br><b>Sent:</b><span class="Apple-converted-space"> </span>13 August 2014 07:50<br><b>To:</b><span class="Apple-converted-space"> </span>Philip K.F. Hölzenspies<br><b>Cc:</b><span class="Apple-converted-space"> </span>Simon Peyton Jones; Edward Kmett;<span class="Apple-converted-space"> </span><a href="mailto:ghc-devs@haskell.org" style="color: purple; text-decoration: underline; ">ghc-devs@haskell.org</a><br><b>Subject:</b><span class="Apple-converted-space"> </span>Re: Broken Data.Data instances<o:p></o:p></span></div></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p> </o:p></div><div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">And I dipped my toes into the phabricator water, and uploaded a diff to<span class="Apple-converted-space"> </span><a href="https://phabricator.haskell.org/D153" style="color: purple; text-decoration: underline; ">https://phabricator.haskell.org/D153</a><o:p></o:p></p></div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">I left the lines long for now, so that it is clear that I simply added parameters to existing type signatures.<o:p></o:p></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p> </o:p></p><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">On Tue, Aug 12, 2014 at 10:51 PM, Alan & Kim Zimmerman <<a href="mailto:alan.zimm@gmail.com" target="_blank" style="color: purple; text-decoration: underline; ">alan.zimm@gmail.com</a>> wrote:<o:p></o:p></p><blockquote style="border-style: none none none solid; border-left-width: 1pt; border-left-color: rgb(204, 204, 204); padding: 0cm 0cm 0cm 6pt; margin-left: 4.8pt; margin-right: 0cm; "><div><div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">Status update<o:p></o:p></p></div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">I have worked through a proof of concept update to the GHC AST whereby the type is provided as a parameter to each data type. This was basically a mechanical process of changing type signatures, and required very little actual code changes, being only to initialise the placeholder types.<o:p></o:p></p></div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">The enabling types are<br><br><o:p></o:p></p><div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">    type PostTcType = Type        -- Used for slots in the abstract syntax<br>                    -- where we want to keep slot for a type<br>                    -- to be added by the type checker...but<br>                    -- [before typechecking it's just bogus]<o:p></o:p></p></div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">    type PreTcType = ()             -- used before typechecking<br><br><br>    class PlaceHolderType a where<br>      placeHolderType :: a<br><br>    instance PlaceHolderType PostTcType where<o:p></o:p></p><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><br>      placeHolderType  = panic "Evaluated the place holder for a PostTcType"<o:p></o:p></p></div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">    instance PlaceHolderType PreTcType where<br>      placeHolderType = ()<br><br>These are used to replace all instances of PostTcType in the hsSyn types.<br><br>The change was applied against HEAD as of last friday, and can be found here<br><br><a href="https://github.com/alanz/ghc/tree/wip/landmine-param" target="_blank" style="color: purple; text-decoration: underline; ">https://github.com/alanz/ghc/tree/wip/landmine-param</a><br><a href="https://github.com/alanz/haddock/tree/wip/landmine-param" target="_blank" style="color: purple; text-decoration: underline; ">https://github.com/alanz/haddock/tree/wip/landmine-param</a><o:p></o:p></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">They pass 'sh validate' with GHC 7.6.3, and compile against GHC 7.8.3. I have not tried to validate that yet, have no reason to expect failure.<br><br><o:p></o:p></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">Can I please get some feedback as to whether this is a worthwhile change?<o:p></o:p></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><br>It is the first step to getting a generic traversal safe AST<o:p></o:p></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">Regards<o:p></o:p></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(136, 136, 136); ">  Alan<o:p></o:p></span></p></div></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p> </o:p></p><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">On Mon, Jul 28, 2014 at 5:45 PM, Alan & Kim Zimmerman <<a href="mailto:alan.zimm@gmail.com" target="_blank" style="color: purple; text-decoration: underline; ">alan.zimm@gmail.com</a>> wrote:<o:p></o:p></p><blockquote style="border-style: none none none solid; border-left-width: 1pt; border-left-color: rgb(204, 204, 204); padding: 0cm 0cm 0cm 6pt; margin-left: 4.8pt; margin-right: 0cm; "><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">FYI I edited the paste at<span class="Apple-converted-space"> </span><a href="http://lpaste.net/108262" target="_blank" style="color: purple; text-decoration: underline; ">http://lpaste.net/108262</a><span class="Apple-converted-space"> </span>to show the problem<o:p></o:p></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p> </o:p></p><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">On Mon, Jul 28, 2014 at 5:41 PM, Alan & Kim Zimmerman <<a href="mailto:alan.zimm@gmail.com" target="_blank" style="color: purple; text-decoration: underline; ">alan.zimm@gmail.com</a>> wrote:<o:p></o:p></p><blockquote style="border-style: none none none solid; border-left-width: 1pt; border-left-color: rgb(204, 204, 204); padding: 0cm 0cm 0cm 6pt; margin-left: 4.8pt; margin-right: 0cm; "><div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">I already tried that, the syntax does not seem to allow it.<br><br>I suspect some higher form of sorcery will be required, as alluded to here<a href="http://stackoverflow.com/questions/14133121/can-i-constrain-a-type-family" target="_blank" style="color: purple; text-decoration: underline; ">http://stackoverflow.com/questions/14133121/can-i-constrain-a-type-family</a><o:p></o:p></p></div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(136, 136, 136); ">Alan</span><o:p></o:p></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p> </o:p></p><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">On Mon, Jul 28, 2014 at 4:55 PM, <<a href="mailto:p.k.f.holzenspies@utwente.nl" target="_blank" style="color: purple; text-decoration: underline; ">p.k.f.holzenspies@utwente.nl</a>> wrote:<o:p></o:p></p><blockquote style="border-style: none none none solid; border-left-width: 1pt; border-left-color: rgb(204, 204, 204); padding: 0cm 0cm 0cm 6pt; margin-left: 4.8pt; margin-right: 0cm; "><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Dear Alan,</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">I would think you would want to constrain the result, i.e.</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">type family (Data (PostTcType a)) => PostTcType a where …</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">The Data-instance of ‘a’ doesn’t give you much if you have a ‘PostTcType a’.</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Your point about SYB-recognition of WrongPhase is, of course, a good one ;)</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Regards,</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Philip</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US"> </span><span lang="NL"><o:p></o:p></span></div><div style="border-style: none none none solid; border-left-width: 1.5pt; border-left-color: blue; padding: 0cm 0cm 0cm 4pt; "><div><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(181, 196, 223); padding: 3pt 0cm 0cm; "><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><b><span lang="EN-US" style="font-size: 10pt; font-family: Tahoma, sans-serif; ">From:</span></b><span lang="EN-US" style="font-size: 10pt; font-family: Tahoma, sans-serif; "><span class="Apple-converted-space"> </span>Alan & Kim Zimmerman [mailto:<a href="mailto:alan.zimm@gmail.com" target="_blank" style="color: purple; text-decoration: underline; ">alan.zimm@gmail.com</a>]<span class="Apple-converted-space"> </span><br><b>Sent:</b><span class="Apple-converted-space"> </span>maandag 28 juli 2014 14:10<br><b>To:</b><span class="Apple-converted-space"> </span>Holzenspies, P.K.F. (EWI)<br><b>Cc:</b><span class="Apple-converted-space"> </span>Simon Peyton Jones; Edward Kmett;<span class="Apple-converted-space"> </span><a href="mailto:ghc-devs@haskell.org" target="_blank" style="color: purple; text-decoration: underline; ">ghc-devs@haskell.org</a></span><span lang="NL"><o:p></o:p></span></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL"><br><b>Subject:</b><span class="Apple-converted-space"> </span>Re: Broken Data.Data instances<o:p></o:p></span></div></div></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL"> <o:p></o:p></span></div><div><div><div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL">Philip<o:p></o:p></span></p></div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL">I think the main reason for the WrongPhase thing is to have something that explicitly has a Data and Typeable instance, to allow generic (SYB) traversal. If we can get by without this so much the better.<o:p></o:p></span></p></div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL">On a related note, is there any way to constrain the 'a' in<br><br>type family PostTcType a where<br>  PostTcType Id    = TcType<br>  PostTcType other = WrongPhaseTyp<o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL">to have an instance of Data?<o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL">I am experimenting with traversals over my earlier paste, and got stuck here (which is the reason the Show instances were commentet out in the original).<o:p></o:p></span></p></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL">Alan<o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL"> <o:p></o:p></span></div></div></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL"> <o:p></o:p></span></p><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL">On Mon, Jul 28, 2014 at 12:30 PM, <<a href="mailto:p.k.f.holzenspies@utwente.nl" target="_blank" style="color: purple; text-decoration: underline; ">p.k.f.holzenspies@utwente.nl</a>> wrote:<o:p></o:p></span></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Sorry about that… I’m having it out with my terminal server and the server seems to be winning. Here’s another go:</span><span lang="NL"><o:p></o:p></span></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">I always read the () as “there’s nothing meaningful to stick in here, but I have to stick in something” so I don’t necessarily want the WrongPhase-thing. There is very old commentary stating it would be lovely if someone could expose the PostTcType as a parameter of the AST-types, but that there are so many types and constructors, that it’s a boring chore to do. Actually, I was hoping haRe would come up to speed to be able to do this. That being said, I think Simon’s idea to turn PostTcType into a type-family is a better way altogether; it also documents intent, i.e. () may not say so much, but PostTcType RdrName says quite a lot.</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Simon commented that a lot of the internal structures aren’t trees, but cyclic graphs, e.g. the TyCon for Maybe references the DataCons for Just and Nothing, which again refer to the TyCon for Maybe. I was wondering whether it would be possible to make stateful lenses for this. Of course, for specific cases, we could do this, but I wonder if it is also possible to have lenses remember the things they visited and not visit them twice. Any ideas on this, Edward?</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Regards,</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Philip</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US"> </span><span lang="NL"><o:p></o:p></span></div><div style="border-style: none none none solid; border-left-width: 1.5pt; border-left-color: blue; padding: 0cm 0cm 0cm 4pt; "><div><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(181, 196, 223); padding: 3pt 0cm 0cm; "><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><b><span lang="EN-US" style="font-size: 10pt; font-family: Tahoma, sans-serif; ">From:</span></b><span lang="EN-US" style="font-size: 10pt; font-family: Tahoma, sans-serif; "><span class="Apple-converted-space"> </span>Alan & Kim Zimmerman [mailto:<a href="mailto:alan.zimm@gmail.com" target="_blank" style="color: purple; text-decoration: underline; ">alan.zimm@gmail.com</a>]</span><span lang="NL"><o:p></o:p></span></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><b><span lang="NL">Sent:</span></b><span lang="NL"><span class="Apple-converted-space"> </span>maandag 28 juli 2014 11:14<o:p></o:p></span></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><b><span lang="NL">To:</span></b><span lang="NL"><span class="Apple-converted-space"> </span>Simon Peyton Jones<br><b>Cc:</b><span class="Apple-converted-space"> </span>Edward Kmett; Holzenspies, P.K.F. (EWI); ghc-devs<o:p></o:p></span></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL"><br><b>Subject:</b><span class="Apple-converted-space"> </span>Re: Broken Data.Data instances<o:p></o:p></span></div></div></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL"> <o:p></o:p></span></div><div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL">I have made a conceptual example of this here<span class="Apple-converted-space"> </span><a href="http://lpaste.net/108262" target="_blank" style="color: purple; text-decoration: underline; ">http://lpaste.net/108262</a><o:p></o:p></span></p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL">Alan<o:p></o:p></span></div></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL"> <o:p></o:p></span></p><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL">On Mon, Jul 28, 2014 at 9:50 AM, Alan & Kim Zimmerman <<a href="mailto:alan.zimm@gmail.com" target="_blank" style="color: purple; text-decoration: underline; ">alan.zimm@gmail.com</a>> wrote:<o:p></o:p></span></div><div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL">What about creating a specific type with a single constructor for the "not relevant to this phase" type to be used instead of () above? That would also clearly document what was going on.<o:p></o:p></span></p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL" style="color: rgb(136, 136, 136); ">Alan</span><span lang="NL"><o:p></o:p></span></div></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL"> <o:p></o:p></span></p><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL">On Mon, Jul 28, 2014 at 9:14 AM, Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank" style="color: purple; text-decoration: underline; ">simonpj@microsoft.com</a>> wrote:<o:p></o:p></span></div><div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt 36pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">I've had to mangle a bunch of hand-written Data instances and push out patches to a dozen packages that used to be built this way before I convinced the authors to switch to safer versions of Data. Using virtual smart constructors like we do now in containers and Text where needed can be used to preserve internal invariants, etc.<span lang="NL"><o:p></o:p></span></p><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">If the “hand grenades” are the PostTcTypes, etc, then I can explain why they are there.  </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">There simply is no sensible type you can put before the type checker runs.  For example one of the constructors  in HsExpr is</span><span lang="NL"><o:p></o:p></span></div><p style="margin-right: 0cm; margin-left: 0cm; font-size: 12pt; font-family: 'Times New Roman', serif; ">  | HsMultiIf   PostTcType [LGRHS id (LHsExpr id)]<span lang="NL"><o:p></o:p></span></p><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">After type checking we know what type the thing has, but before we have no clue.</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">We could get around this by saying</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">            type PostTcType = Maybe TcType</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">but that would mean that every post-typechecking consumer would need a redundant pattern-match on a Just that would always succeed.</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">It’s nothing deeper than that.  Adding Maybes everywhere would be possible, just clunky.</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">However we now have type functions, and HsExpr is parameterised by an ‘id’ parameter, which changes from RdrName (after parsing) to Name (after renaming) to Id (after typechecking).  So we could do this:</span><span lang="NL"><o:p></o:p></span></div><p style="margin-right: 0cm; margin-left: 0cm; font-size: 12pt; font-family: 'Times New Roman', serif; ">  | HsMultiIf   (PostTcType id) [LGRHS id (LHsExpr id)]<span lang="NL"><o:p></o:p></span></p><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">and define PostTcType as a closed type family thus</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><p style="margin-right: 0cm; margin-left: 0cm; font-size: 12pt; font-family: 'Times New Roman', serif; ">     type family PostTcType a where<span lang="NL"><o:p></o:p></span></p><p style="margin-right: 0cm; margin-left: 0cm; font-size: 12pt; font-family: 'Times New Roman', serif; ">          PostTcType Id = TcType<span lang="NL"><o:p></o:p></span></p><p style="margin-right: 0cm; margin-left: 0cm; font-size: 12pt; font-family: 'Times New Roman', serif; ">          PostTcType other = ()<span lang="NL"><o:p></o:p></span></p><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">That would be better than filling it with bottoms.  But it might not help with generic programming, because there’d be a component whose type wasn’t fixed.  I have no idea how generics and type functions interact.</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Simon</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="border-style: none none none solid; border-left-width: 1.5pt; border-left-color: blue; padding: 0cm 0cm 0cm 4pt; "><div><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0cm 0cm; "><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><b><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; ">From:</span></b><span lang="EN-US" style="font-size: 11pt; font-family: Calibri, sans-serif; "><span class="Apple-converted-space"> </span>Edward Kmett [mailto:<a href="mailto:ekmett@gmail.com" target="_blank" style="color: purple; text-decoration: underline; ">ekmett@gmail.com</a>]<span class="Apple-converted-space"> </span><br><b>Sent:</b><span class="Apple-converted-space"> </span>27 July 2014 18:27<br><b>To:</b><span class="Apple-converted-space"> </span><a href="mailto:p.k.f.holzenspies@utwente.nl" target="_blank" style="color: purple; text-decoration: underline; ">p.k.f.holzenspies@utwente.nl</a><br><b>Cc:</b><span class="Apple-converted-space"> </span><a href="mailto:alan.zimm@gmail.com" target="_blank" style="color: purple; text-decoration: underline; ">alan.zimm@gmail.com</a>; Simon Peyton Jones; ghc-devs</span><span lang="NL"><o:p></o:p></span></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><br><b>Subject:</b><span class="Apple-converted-space"> </span>Re: Broken Data.Data instances<span lang="NL"><o:p></o:p></span></div></div></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "> <span lang="NL"><o:p></o:p></span></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">Philip, Alan, <span lang="NL"><o:p></o:p></span></p><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "> <span lang="NL"><o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">If you need a hand, I'm happy to pitch in guidance. <span lang="NL"><o:p></o:p></span></p><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "> <span lang="NL"><o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">I've had to mangle a bunch of hand-written Data instances and push out patches to a dozen packages that used to be built this way before I convinced the authors to switch to safer versions of Data. Using virtual smart constructors like we do now in containers and Text where needed can be used to preserve internal invariants, etc.<span lang="NL"><o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "> <span lang="NL"><o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">This works far better for users of the API than just randomly throwing them a live hand grenade. As I recall, these little grenades in generic programming over the GHC API have been a constant source of pain for libraries like haddock.<span lang="NL"><o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "> <span lang="NL"><o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">Simon,<span lang="NL"><o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "> <span lang="NL"><o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">It seems to me that regarding circular data structures, nothing prevents you from walking a circular data structure with Data.Data. You can generate a new one productively that looks just like the old with the contents swapped out, it is indistinguishable to an observer if the fixed point is lost, and a clever observer can use observable sharing to get it back, supposing that they are allowed to try.<span lang="NL"><o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "> <span lang="NL"><o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">Alternately, we could use the 'virtual constructor' trick there to break the cycle and reintroduce it, but I'm less enthusiastic about that idea, even if it is simpler in many ways.<span lang="NL"><o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "> <span lang="NL"><o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">-Edward<span lang="NL"><o:p></o:p></span></p></div></div></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "> <span lang="NL"><o:p></o:p></span></p><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">On Sun, Jul 27, 2014 at 10:17 AM, <<a href="mailto:p.k.f.holzenspies@utwente.nl" target="_blank" style="color: purple; text-decoration: underline; ">p.k.f.holzenspies@utwente.nl</a>> wrote:<span lang="NL"><o:p></o:p></span></p><blockquote style="border-style: none none none solid; border-left-width: 1pt; border-left-color: rgb(204, 204, 204); padding: 0cm 0cm 0cm 6pt; margin: 5pt 0cm 5pt 4.8pt; "><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-size: 10pt; font-family: Tahoma, sans-serif; ">Alan,<br><br>In that case, let's have a short feedback-loop between the two of us. It seems many of these files (Name.lhs, for example) are really stable through the repo-history. It would be nice to have one bigger refactoring all in one go (some of the code could use a polish, a lot of code seems removable).<br><br>Regards,<br>Philip</span><span lang="NL"><o:p></o:p></span></p><div><div style="margin-bottom: 6pt; "><div class="MsoNormal" align="center" style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; text-align: center; "><span style=""><hr size="2" width="100%" align="center"></span></div></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><b><span style="font-family: Tahoma, sans-serif; ">Van:</span></b><span style="font-family: Tahoma, sans-serif; "><span class="Apple-converted-space"> </span>Alan & Kim Zimmerman [<a href="mailto:alan.zimm@gmail.com" target="_blank" style="color: purple; text-decoration: underline; ">alan.zimm@gmail.com</a>]<br><b>Verzonden:</b><span class="Apple-converted-space"> </span>vrijdag 25 juli 2014 13:44<br><b>Aan:</b><span class="Apple-converted-space"> </span>Simon Peyton Jones<br><b>CC:</b><span class="Apple-converted-space"> </span>Holzenspies, P.K.F. (EWI);<span class="Apple-converted-space"> </span><a href="mailto:ghc-devs@haskell.org" target="_blank" style="color: purple; text-decoration: underline; ">ghc-devs@haskell.org</a><br><b>Onderwerp:</b><span class="Apple-converted-space"> </span>Re: Broken Data.Data instances</span><span lang="NL"><o:p></o:p></span></p></div><div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">By the way, I would be happy to attempt this task, if the concept is viable.</span><span lang="NL"><o:p></o:p></span></p></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=""> </span><span lang="NL"><o:p></o:p></span></p><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">On Thu, Jul 24, 2014 at 11:23 PM, Alan & Kim Zimmerman <<a href="mailto:alan.zimm@gmail.com" target="_blank" style="color: purple; text-decoration: underline; ">alan.zimm@gmail.com</a>> wrote:</span><span lang="NL"><o:p></o:p></span></p><blockquote style="border-style: none none none solid; border-left-width: 1pt; border-left-color: rgb(204, 204, 204); padding: 0cm 0cm 0cm 6pt; margin: 5pt 0cm 5pt 4.8pt; "><div><div><div><div><div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">While we are talking about fixing traversals, how about getting rid of the phase specific panic initialisers for placeHolderType, placeHolderKind and friends?</span><span lang="NL"><o:p></o:p></span></p></div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">In order to safely traverse with SYB, the following needs to be inserted into all the SYB schemes (see<span class="Apple-converted-space"> </span><br><a href="https://github.com/alanz/HaRe/blob/master/src/Language/Haskell/Refact/Utils/GhcUtils.hs" target="_blank" style="color: purple; text-decoration: underline; ">https://github.com/alanz/HaRe/blob/master/src/Language/Haskell/Refact/Utils/GhcUtils.hs</a>)<br><br>-- Check the Typeable items<br>checkItemStage1 :: (Typeable a) => SYB.Stage -> a -> Bool<br>checkItemStage1 stage x = (const False `SYB.extQ` postTcType `SYB.extQ` fixity `SYB.extQ` nameSet) x<br>  where nameSet     = const (stage `elem` [SYB.Parser,SYB.TypeChecker]) :: GHC.NameSet       -> Bool<br>        postTcType  = const (stage < SYB.TypeChecker                  ) :: GHC.PostTcType    -> Bool<br>        fixity      = const (stage < SYB.Renamer                      ) :: GHC.Fixity        -> Bool</span><span lang="NL"><o:p></o:p></span></p></div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">And in addition HsCmdTop and ParStmtBlock are initialised with explicit 'undefined values.</span><span lang="NL"><o:p></o:p></span></p></div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">Perhaps use an initialiser that can have its panic turned off when called via the GHC API?</span><span lang="NL"><o:p></o:p></span></p></div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">Regards</span><span lang="NL"><o:p></o:p></span></p></div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">  Alan</span><span lang="NL"><o:p></o:p></span></p><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=""> </span><span lang="NL"><o:p></o:p></span></p></div></div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=""> </span><span lang="NL"><o:p></o:p></span></p><div><div><p class="MsoNormal" style="margin: 0cm 0cm 6pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">On Thu, Jul 24, 2014 at 11:06 PM, Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank" style="color: purple; text-decoration: underline; ">simonpj@microsoft.com</a>> wrote:</span><span lang="NL"><o:p></o:p></span></p></div><blockquote style="border-style: none none none solid; border-left-width: 1pt; border-left-color: rgb(204, 204, 204); padding: 0cm 0cm 0cm 6pt; margin: 5pt 0cm 5pt 4.8pt; "><div><div><div><p class="MsoNormal" style="margin: 0cm 0cm 12pt 36pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">So... does anyone object to me changing these "broken" instances with the ones given by DeriveDataTypeable?</span><span lang="NL"><o:p></o:p></span></p></div><div style="margin: 0cm 0cm 0.0001pt 4.9pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">That’s fine with me provided (a) the default behaviour is not immediate divergence (which it might well be), and (b) the pitfalls are documented.</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 4.9pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=""> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt 4.9pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">Simon</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="border-style: none none none solid; border-left-width: 1.5pt; border-left-color: blue; padding: 0cm 0cm 0cm 4pt; "><div><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0cm 0cm; "><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><b><span lang="EN-US">From:</span></b><span lang="EN-US"><span class="Apple-converted-space"> </span>"Philip K.F. Hölzenspies" [mailto:<a href="mailto:p.k.f.holzenspies@utwente.nl" target="_blank" style="color: purple; text-decoration: underline; ">p.k.f.holzenspies@utwente.nl</a>]<span class="Apple-converted-space"> </span><br><b>Sent:</b><span class="Apple-converted-space"> </span>24 July 2014 18:42<br><b>To:</b><span class="Apple-converted-space"> </span>Simon Peyton Jones<br><b>Cc:</b><span class="Apple-converted-space"> </span><a href="mailto:ghc-devs@haskell.org" target="_blank" style="color: purple; text-decoration: underline; ">ghc-devs@haskell.org</a><br><b>Subject:</b><span class="Apple-converted-space"> </span>Re: Broken Data.Data instances</span><span lang="NL"><o:p></o:p></span></div></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=""> </span><span lang="NL"><o:p></o:p></span></div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">Dear Simon, et al,<br><br>These are very good points to make for people writing such traversals and queries. I would be more than happy to write a page on the pitfalls etc. on the wiki, but in my experience so far, exploring the innards of GHC is tremendously helped by trying small things out and showing (bits of) the intermediate structures. For me, personally, this has always been hindered by the absence of good instances of Data and/or Show (not having to bring DynFlags and not just visualising with the pretty printer are very helpful).<br><br>So... does anyone object to me changing these "broken" instances with the ones given by DeriveDataTypeable?<br><br>Also, many of these internal data structures could be provided with useful lenses to improve such traversals further. Anyone ever go at that? Would be people be interested?<br><br>Regards,<br>Philip</span><span lang="NL"><o:p></o:p></span></p><blockquote style="margin-top: 5pt; margin-bottom: 5pt; "><div style="margin: 22.5pt 18.75pt 7.5pt; "><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(237, 238, 240); padding: 4pt 0cm 0cm; display: table; "><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; vertical-align: middle; "><span style=""><image001.jpg></span><span lang="NL"><o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; vertical-align: middle; "><span style=""><a href="mailto:simonpj@microsoft.com" target="_blank" style="color: purple; text-decoration: underline; "><b>Simon Peyton Jones</b></a></span><span lang="NL"><o:p></o:p></span></div></div><div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; vertical-align: middle; "><span style="color: rgb(159, 162, 165); ">24 Jul 2014 18:22</span><span lang="NL"><o:p></o:p></span></div></div></div></div><div style="margin-left: 18pt; margin-right: 18pt; "><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(31, 73, 125); ">GHC’s data structures are often mutually recursive. e.g.</span><span lang="NL"><o:p></o:p></span></div><p style="margin-right: 0cm; margin-left: 0cm; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Symbol; color: rgb(136, 136, 136); ">·</span><span style="font-size: 7pt; color: rgb(136, 136, 136); ">       <span class="Apple-converted-space"> </span></span><span style="color: rgb(31, 73, 125); ">The TyCon for Maybe contains the DataCon for Just</span><span lang="NL"><o:p></o:p></span></p><p style="margin-right: 0cm; margin-left: 0cm; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Symbol; color: rgb(136, 136, 136); ">·</span><span style="font-size: 7pt; color: rgb(136, 136, 136); ">       <span class="Apple-converted-space"> </span></span><span style="color: rgb(31, 73, 125); ">The DataCon For just contains Just’s type</span><span lang="NL"><o:p></o:p></span></p><p style="margin-right: 0cm; margin-left: 0cm; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-family: Symbol; color: rgb(136, 136, 136); ">·</span><span style="font-size: 7pt; color: rgb(136, 136, 136); ">       <span class="Apple-converted-space"> </span></span><span style="color: rgb(31, 73, 125); ">Just’s type contains the TyCon for Maybe</span><span lang="NL"><o:p></o:p></span></p><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(31, 73, 125); ">So any attempt to recursively walk over all these structures, as you would a tree, will fail. </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(31, 73, 125); ">Also there’s a lot of sharing.  For example, every occurrence of ‘map’ is a Var, and inside that Var is map’s type, its strictness, its rewrite RULE, etc etc.  In walking over a term you may not want to walk over all that stuff at every occurrence of map.</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(31, 73, 125); ">Maybe that’s it; I’m not certain since I did not write the Data instances for any of GHC’s types</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(31, 73, 125); ">Simon</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="color: rgb(31, 73, 125); "> </span><span lang="NL"><o:p></o:p></span></div><div style="border-style: none none none solid; border-left-width: 1.5pt; border-left-color: blue; padding: 0cm 0cm 0cm 4pt; "><div><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0cm 0cm; "><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><b><span lang="EN-US" style="">From:</span></b><span lang="EN-US" style=""><span class="Apple-converted-space"> </span>ghc-devs [<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank" style="color: purple; text-decoration: underline; ">mailto:ghc-devs-bounces@haskell.org</a>]<span class="Apple-converted-space"> </span><b>On Behalf Of</b><a href="mailto:p.k.f.holzenspies@utwente.nl" target="_blank" style="color: purple; text-decoration: underline; ">p.k.f.holzenspies@utwente.nl</a><br><b>Sent:</b><span class="Apple-converted-space"> </span>24 July 2014 16:42<br><b>To:</b><span class="Apple-converted-space"> </span><a href="mailto:ghc-devs@haskell.org" target="_blank" style="color: purple; text-decoration: underline; ">ghc-devs@haskell.org</a><br><b>Subject:</b><span class="Apple-converted-space"> </span>Broken Data.Data instances</span><span lang="NL"><o:p></o:p></span></div></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=""> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">Dear GHC-ers,</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style=""> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">Is there a reason for explicitly broken Data.Data instances? Case in point:</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style=""> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">> instance Data Var where</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">>   -- don't traverse?</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">>   toConstr _   = abstractConstr "Var"</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">>   gunfold _ _  = error "gunfold"</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">>   dataTypeOf _ = mkNoRepType "Var"</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style=""> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">I understand (vaguely) arguments about abstract data types, but this also excludes convenient queries that can, e.g. extract all types from a CoreExpr. I had hoped to do stuff like this:</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style=""> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">> collect :: (Typeable b, Data a, MonadPlus m) => a -> m b</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">> collect = everything mplus $ mkQ mzero return</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">> allTypes :: CoreExpr -> [Type]</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">> allTypes = collect</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style=""> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">Especially when still exploring (parts of) the GHC API, being able to extract things in this fashion is very helpful. SYB’s “everything” being broken by these instances, not so much.</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style=""> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">Would a patch “fixing” these instances be acceptable?</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style=""> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">Regards,</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style="">Philip</span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style=""> </span><span lang="NL"><o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="EN-US" style=""> </span><span lang="NL"><o:p></o:p></span></div></div></div></blockquote></div></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=""> </span><span lang="NL"><o:p></o:p></span></div></div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="">_______________________________________________<br>ghc-devs mailing list<br><a href="mailto:ghc-devs@haskell.org" target="_blank" style="color: purple; text-decoration: underline; ">ghc-devs@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank" style="color: purple; text-decoration: underline; ">http://www.haskell.org/mailman/listinfo/ghc-devs</a></span><span lang="NL"><o:p></o:p></span></p></blockquote></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=""> </span><span lang="NL"><o:p></o:p></span></div></div></blockquote></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=""> </span><span lang="NL"><o:p></o:p></span></div></div></div></div></div><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><br>_______________________________________________<br>ghc-devs mailing list<br><a href="mailto:ghc-devs@haskell.org" target="_blank" style="color: purple; text-decoration: underline; ">ghc-devs@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank" style="color: purple; text-decoration: underline; ">http://www.haskell.org/mailman/listinfo/ghc-devs</a><span lang="NL"><o:p></o:p></span></p></blockquote></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "> <span lang="NL"><o:p></o:p></span></div></div></div></div></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL"> <o:p></o:p></span></div></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL"> <o:p></o:p></span></div></div></div></div></div></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span lang="NL"> <o:p></o:p></span></div></div></div></div></blockquote></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p> </o:p></div></div></blockquote></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p> </o:p></div></div></blockquote></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p> </o:p></div></div></blockquote></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p> </o:p></div></div></div></div>_______________________________________________<br>ghc-devs mailing list<br><a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>http://www.haskell.org/mailman/listinfo/ghc-devs</div></blockquote></div><br></body></html>