<div dir="ltr"><div><div>Status update<br><br></div>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.<br>

<br></div>The enabling types are<br><br><br><div>    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]<br>    type PreTcType = ()             -- used before typechecking<br><br><br>    class PlaceHolderType a where<br>      placeHolderType :: a<br><br>    instance PlaceHolderType PostTcType where<br>

      placeHolderType  = panic "Evaluated the place holder for a PostTcType"<br><br>    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">https://github.com/alanz/ghc/tree/wip/landmine-param</a><br><a href="https://github.com/alanz/haddock/tree/wip/landmine-param">https://github.com/alanz/haddock/tree/wip/landmine-param</a><br>

<br></div><div>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><br></div><div>Can I please get some feedback as to whether this is a worthwhile change?<br>

</div><div><br>It is the first step to getting a generic traversal safe AST<br><br></div><div>Regards<br></div><div>  Alan<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 28, 2014 at 5:45 PM, 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">FYI I edited the paste at <a href="http://lpaste.net/108262" target="_blank">http://lpaste.net/108262</a> to show the problem<br>

</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 28, 2014 at 5:41 PM, 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>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">http://stackoverflow.com/questions/14133121/can-i-constrain-a-type-family</a><span><font color="#888888"><br>



<br></font></span></div><span><font color="#888888">Alan<br></font></span></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 28, 2014 at 4:55 PM,  <span dir="ltr"><<a href="mailto:p.k.f.holzenspies@utwente.nl" target="_blank">p.k.f.holzenspies@utwente.nl</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div link="blue" vlink="purple" lang="NL">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Dear Alan,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US">I would think you would want to constrain the result, i.e.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US">type family (Data (PostTcType a)) => PostTcType a where …<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US">The Data-instance of ‘a’ doesn’t give you much if you have a ‘PostTcType a’.<u></u><u></u></span></p>




<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US">Your point about SYB-recognition of WrongPhase is, of course, a good one ;)<u></u><u></u></span></p>




<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US">Regards,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US">Philip<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" lang="EN-US">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" lang="EN-US"> Alan & Kim Zimmerman [mailto:<a href="mailto:alan.zimm@gmail.com" target="_blank">alan.zimm@gmail.com</a>]
<br>
<b>Sent:</b> maandag 28 juli 2014 14:10<br>
<b>To:</b> Holzenspies, P.K.F. (EWI)<br>
<b>Cc:</b> Simon Peyton Jones; Edward Kmett; <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a></span></p><div><div><br>
<b>Subject:</b> Re: Broken Data.Data instances<u></u><u></u></div></div><p></p>
</div>
</div><div><div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Philip<u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">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.<u></u><u></u></p>




</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">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<br>
<br>
<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">to have an instance of Data?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">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).<u></u><u></u></p>




</div>
<div>
<p class="MsoNormal">Alan<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Mon, Jul 28, 2014 at 12:30 PM, <<a href="mailto:p.k.f.holzenspies@utwente.nl" target="_blank">p.k.f.holzenspies@utwente.nl</a>> wrote:<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US">Sorry about that… I’m having it out with my terminal server and the server seems to
 be winning. Here’s another go:</span><u></u><u></u></p>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US">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><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US"> </span><u></u><u></u></p>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US">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><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US">Regards,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US">Philip</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US"> </span><u></u><u></u></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" lang="EN-US">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" lang="EN-US"> Alan
 & Kim Zimmerman [mailto:<a href="mailto:alan.zimm@gmail.com" target="_blank">alan.zimm@gmail.com</a>]
</span><u></u><u></u></p>
<div>
<p class="MsoNormal"><b>Sent:</b> maandag 28 juli 2014 11:14<u></u><u></u></p>
</div>
<p class="MsoNormal"><b>To:</b> Simon Peyton Jones<br>
<b>Cc:</b> Edward Kmett; Holzenspies, P.K.F. (EWI); ghc-devs<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><br>
<b>Subject:</b> Re: Broken Data.Data instances<u></u><u></u></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">I have made a conceptual example of this here
<a href="http://lpaste.net/108262" target="_blank">http://lpaste.net/108262</a><u></u><u></u></p>
</div>
<p class="MsoNormal">Alan<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Mon, Jul 28, 2014 at 9:50 AM, Alan & Kim Zimmerman <<a href="mailto:alan.zimm@gmail.com" target="_blank">alan.zimm@gmail.com</a>> wrote:<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">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.<u></u><u></u></p>
</div>
<p class="MsoNormal"><span style="color:#888888">Alan</span><u></u><u></u></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Mon, Jul 28, 2014 at 9:14 AM, Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>> wrote:<u></u><u></u></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt;margin-left:36.0pt">
<span lang="EN-GB">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><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
</div>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">If the “hand grenades” are the PostTcTypes, etc, then I can explain why they are there.  
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">There simply is no sensible type you can put before the type checker runs.  For example one of the constructors 
 in HsExpr is</span><u></u><u></u></p>
<p><span lang="EN-GB">  | HsMultiIf   PostTcType [LGRHS id (LHsExpr id)]</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">After type checking we know what type the thing has, but before we have no clue.</span><u></u><u></u></p>




<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">We could get around this by saying</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">            type PostTcType = Maybe TcType</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">but that would mean that every post-typechecking consumer would need a redundant pattern-match on a Just
 that would always succeed.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">It’s nothing deeper than that.  Adding Maybes everywhere would be possible, just clunky.</span><u></u><u></u></p>




<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">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><u></u><u></u></p>
<p><span lang="EN-GB">  | HsMultiIf   (PostTcType id) [LGRHS id (LHsExpr id)]</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">and define PostTcType as a closed type family thus</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<p><span lang="EN-GB">     type family PostTcType a where</span><u></u><u></u></p>
<p><span lang="EN-GB">          PostTcType Id = TcType</span><u></u><u></u></p>
<p><span lang="EN-GB">          PostTcType other = ()</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">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><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">Simon</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"" lang="EN-US">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"" lang="EN-US">
 Edward Kmett [mailto:<a href="mailto:ekmett@gmail.com" target="_blank">ekmett@gmail.com</a>]
<br>
<b>Sent:</b> 27 July 2014 18:27<br>
<b>To:</b> <a href="mailto:p.k.f.holzenspies@utwente.nl" target="_blank">p.k.f.holzenspies@utwente.nl</a><br>
<b>Cc:</b> <a href="mailto:alan.zimm@gmail.com" target="_blank">alan.zimm@gmail.com</a>; Simon Peyton Jones; ghc-devs</span><u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><span lang="EN-GB"><br>
<b>Subject:</b> Re: Broken Data.Data instances</span><u></u><u></u></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-GB"> </span><u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB">Philip, Alan, </span><u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> </span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB">If you need a hand, I'm happy to pitch in guidance. </span><u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> </span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB">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><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> </span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB">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><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> </span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB">Simon,</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> </span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB">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><u></u><u></u></p>




</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> </span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB">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><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> </span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB">-Edward</span><u></u><u></u></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span lang="EN-GB"> </span><u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB">On Sun, Jul 27, 2014 at 10:17 AM, <<a href="mailto:p.k.f.holzenspies@utwente.nl" target="_blank">p.k.f.holzenspies@utwente.nl</a>> wrote:</span><u></u><u></u></p>




<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:black" lang="EN-GB">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><u></u><u></u></p>
<div>
<div style="margin-bottom:6.0pt">
<div class="MsoNormal" style="text-align:center" align="center"><span style="color:black" lang="EN-GB">
<hr align="center" size="2" width="100%">
</span></div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-family:"Tahoma","sans-serif";color:black" lang="EN-GB">Van:</span></b><span style="font-family:"Tahoma","sans-serif";color:black" lang="EN-GB"> Alan & Kim Zimmerman
 [<a href="mailto:alan.zimm@gmail.com" target="_blank">alan.zimm@gmail.com</a>]<br>
<b>Verzonden:</b> vrijdag 25 juli 2014 13:44<br>
<b>Aan:</b> Simon Peyton Jones<br>
<b>CC:</b> Holzenspies, P.K.F. (EWI); <a href="mailto:ghc-devs@haskell.org" target="_blank">
ghc-devs@haskell.org</a><br>
<b>Onderwerp:</b> Re: Broken Data.Data instances</span><u></u><u></u></p>
</div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span style="color:black" lang="EN-GB">By the way, I would be happy to attempt this task, if the concept is viable.</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="color:black" lang="EN-GB"> </span><u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span style="color:black" lang="EN-GB">On Thu, Jul 24, 2014 at 11:23 PM, Alan & Kim Zimmerman <<a href="mailto:alan.zimm@gmail.com" target="_blank">alan.zimm@gmail.com</a>> wrote:</span><u></u><u></u></p>




<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="color:black" lang="EN-GB">While we are talking about fixing traversals, how about getting rid of the phase specific panic initialisers for placeHolderType, placeHolderKind
 and friends?</span><u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="color:black" lang="EN-GB">In order to safely traverse with SYB, the following needs to be inserted into all the SYB schemes (see
<br>
<a href="https://github.com/alanz/HaRe/blob/master/src/Language/Haskell/Refact/Utils/GhcUtils.hs" target="_blank">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><u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="color:black" lang="EN-GB">And in addition HsCmdTop and ParStmtBlock are initialised with explicit 'undefined values.</span><u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="color:black" lang="EN-GB">Perhaps use an initialiser that can have its panic turned off when called via the GHC API?</span><u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span style="color:black" lang="EN-GB">Regards</span><u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span style="color:black" lang="EN-GB">  Alan</span><u></u><u></u></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span style="color:black" lang="EN-GB"> </span><u></u><u></u></p>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="color:black" lang="EN-GB"> </span><u></u><u></u></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span style="color:black" lang="EN-GB">On Thu, Jul 24, 2014 at 11:06 PM, Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>> wrote:</span><u></u><u></u></p>




</div>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt;margin-left:36.0pt">
<span style="color:black" lang="EN-GB">So... does anyone object to me changing these "broken" instances with the ones given by DeriveDataTypeable?</span><u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-left:4.9pt">
<span style="color:black" lang="EN-GB">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><u></u><u></u></p>
<p class="MsoNormal" style="margin-left:4.9pt">
<span style="color:black" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal" style="margin-left:4.9pt">
<span style="color:black" lang="EN-GB">Simon</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> "Philip K.F. Hölzenspies" [mailto:<a href="mailto:p.k.f.holzenspies@utwente.nl" target="_blank">p.k.f.holzenspies@utwente.nl</a>]
<br>
<b>Sent:</b> 24 July 2014 18:42<br>
<b>To:</b> Simon Peyton Jones<br>
<b>Cc:</b> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<b>Subject:</b> Re: Broken Data.Data instances</span><u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="color:black" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="color:black" lang="EN-GB">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><u></u><u></u></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div style="margin-left:18.75pt;margin-top:22.5pt;margin-right:18.75pt;margin-bottom:7.5pt">
<div style="border:none;border-top:solid #edeef0 1.0pt;padding:4.0pt 0cm 0cm 0cm;display:table">
<div>
<p class="MsoNormal" style="vertical-align:middle">
<span style="color:black" lang="EN-GB"><img src="cid:image001.jpg@01CFAA84.C621E9B0" name="1477da62e8e96587_1477da2765791a62_1477d789d54216e0_1477c8590141b1b0_1477bf2eb0621629_1477bd31b64563e9_14778343d57bebd6_1476a41e02e48ee6_1476a3317799b7c6_postbox-contact.jpg" height="25" border="0" width="25"></span><u></u><u></u></p>




</div>
<div>
<p class="MsoNormal" style="vertical-align:middle">
<span style="color:black" lang="EN-GB"><a href="mailto:simonpj@microsoft.com" target="_blank"><b>Simon Peyton Jones</b></a></span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="vertical-align:middle">
<span style="color:#9fa2a5" lang="EN-GB">24 Jul 2014 18:22</span><u></u><u></u></p>
</div>
</div>
</div>
<div style="margin-left:18.0pt;margin-right:18.0pt">
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">GHC’s data structures are often mutually recursive. e.g.</span><u></u><u></u></p>
<p><span style="font-family:Symbol;color:#888888" lang="EN-GB">·</span><span style="font-size:7.0pt;color:#888888" lang="EN-GB">       
</span><span style="color:#1f497d" lang="EN-GB">The TyCon for Maybe contains the DataCon for Just</span><u></u><u></u></p>
<p><span style="font-family:Symbol;color:#888888" lang="EN-GB">·</span><span style="font-size:7.0pt;color:#888888" lang="EN-GB">       
</span><span style="color:#1f497d" lang="EN-GB">The DataCon For just contains Just’s type</span><u></u><u></u></p>
<p><span style="font-family:Symbol;color:#888888" lang="EN-GB">·</span><span style="font-size:7.0pt;color:#888888" lang="EN-GB">       
</span><span style="color:#1f497d" lang="EN-GB">Just’s type contains the TyCon for Maybe</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">So any attempt to recursively walk over all these structures, as you would a tree, will fail. 
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">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><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">Maybe that’s it; I’m not certain since I did not write the Data instances for any of GHC’s types</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">Simon</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span><u></u><u></u></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="color:black" lang="EN-US">From:</span></b><span style="color:black" lang="EN-US"> ghc-devs [<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">mailto:ghc-devs-bounces@haskell.org</a>]
<b>On Behalf Of </b><a href="mailto:p.k.f.holzenspies@utwente.nl" target="_blank">p.k.f.holzenspies@utwente.nl</a><br>
<b>Sent:</b> 24 July 2014 16:42<br>
<b>To:</b> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<b>Subject:</b> Broken Data.Data instances</span><u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><span style="color:black" lang="EN-GB"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">Dear GHC-ers,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">Is there a reason for explicitly broken Data.Data instances? Case in point:</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">> instance Data Var where</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">>   -- don't traverse?</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">>   toConstr _   = abstractConstr "Var"</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">>   gunfold _ _  = error "gunfold"</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">>   dataTypeOf _ = mkNoRepType "Var"</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">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><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">> collect :: (Typeable b, Data a, MonadPlus m) => a -> m b</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">> collect = everything mplus $ mkQ mzero return</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">> allTypes :: CoreExpr -> [Type]</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">> allTypes = collect</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">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><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">Would a patch “fixing” these instances be acceptable?</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">Regards,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">Philip</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><u></u><u></u></p>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><span style="color:black" lang="EN-GB"> </span><u></u><u></u></p>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="color:black" lang="EN-GB">_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">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></span><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><span style="color:black" lang="EN-GB"> </span><u></u><u></u></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><span style="color:black" lang="EN-GB"> </span><u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span lang="EN-GB"><br>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">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></span><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><span lang="EN-GB"> </span><u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></div></div>
</div>
</div>

</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>