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

<br></div>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><br></div><div>to have an instance of Data?<br>

<br></div><div>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).<br><br></div><div>Alan<br></div><div><br></div></div>

<div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 28, 2014 at 12:30 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" 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:<u></u><u></u></span></p>

<div class="">
<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">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.<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>
</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?<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 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>
<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></span></p><div class="">
<b>Sent:</b> maandag 28 juli 2014 11:14<br>
</div><b>To:</b> Simon Peyton Jones<br>
<b>Cc:</b> Edward Kmett; Holzenspies, P.K.F. (EWI); ghc-devs<div><div class="h5"><br>
<b>Subject:</b> Re: Broken Data.Data instances<u></u><u></u></div></div><p></p>
</div>
</div><div><div class="h5">
<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><span style="color:#888888">Alan</span></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.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
<p><span lang="EN-GB">  | HsMultiIf   PostTcType [LGRHS id (LHsExpr id)]<u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>


<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">We could get around this by saying</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">            type PostTcType = Maybe TcType</span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>


<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
<p><span lang="EN-GB">  | HsMultiIf   (PostTcType id) [LGRHS id (LHsExpr id)]<u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></p>
<p><span lang="EN-GB">     type family PostTcType a where<u></u><u></u></span></p>
<p><span lang="EN-GB">          PostTcType Id = TcType<u></u><u></u></span></p>
<p><span lang="EN-GB">          PostTcType other = ()<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB">Simon</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri","sans-serif";color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><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 #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><span lang="EN-GB"><u></u><u></u></span></p>
<div>
<div>
<p class="MsoNormal"><span lang="EN-GB"><br>
<b>Subject:</b> Re: Broken Data.Data instances<u></u><u></u></span></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span lang="EN-GB"> <u></u><u></u></span></p>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB">Philip, Alan, <u></u><u></u></span></p>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> <u></u><u></u></span></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. <u></u><u></u></span></p>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> <u></u><u></u></span></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.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> <u></u><u></u></span></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.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB">Simon,<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> <u></u><u></u></span></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.<u></u><u></u></span></p>


</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> <u></u><u></u></span></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.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB"> <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span lang="EN-GB">-Edward<u></u><u></u></span></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span lang="EN-GB"> <u></u><u></u></span></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:<u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="color:black" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>


</div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span style="color:black" lang="EN-GB">Regards</span><span lang="EN-GB"><u></u><u></u></span></p>
</div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span style="color:black" lang="EN-GB">  Alan</span><span lang="EN-GB"><u></u><u></u></span></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:6.0pt"><span style="color:black" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></p>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="color:black" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>


<p class="MsoNormal" style="margin-left:4.9pt">
<span style="color:black" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:4.9pt">
<span style="color:black" lang="EN-GB">Simon</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><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 #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><span lang="EN-GB"><u></u><u></u></span></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span style="color:black" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></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@01CFAA5F.B8814B90" name="1477c8590141b1b0_1477bf2eb0621629_1477bd31b64563e9_14778343d57bebd6_1476a41e02e48ee6_1476a3317799b7c6_postbox-contact.jpg" border="0" height="25" width="25"></span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="vertical-align:middle">
<span style="color:#9fa2a5" lang="EN-GB">24 Jul 2014 18:22</span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB">Simon</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d" lang="EN-GB"> </span><span lang="EN-GB"><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 #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><span lang="EN-GB"><u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><span style="color:black" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">Dear GHC-ers,</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">> instance Data Var where</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">>   -- don't traverse?</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">>   toConstr _   = abstractConstr "Var"</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">>   gunfold _ _  = error "gunfold"</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">>   dataTypeOf _ = mkNoRepType "Var"</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">> collect :: (Typeable b, Data a, MonadPlus m) => a -> m b</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">> collect = everything mplus $ mkQ mzero return</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">> </span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">> allTypes :: CoreExpr -> [Type]</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">> allTypes = collect</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">Would a patch “fixing” these instances be acceptable?</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">Regards,</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US">Philip</span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><span lang="EN-GB"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black" lang="EN-US"> </span><span lang="EN-GB"><u></u><u></u></span></p>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><span style="color:black" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></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><span lang="EN-GB"><u></u><u></u></span></p>
</blockquote>
</div>
<p class="MsoNormal"><span style="color:black" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><span style="color:black" lang="EN-GB"> </span><span lang="EN-GB"><u></u><u></u></span></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><u></u><u></u></span></p>
</blockquote>
</div>
<p class="MsoNormal"><span lang="EN-GB"> <u></u><u></u></span></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>

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