<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi devs,<div class=""><br class=""></div><div class="">I just came across [TTG: Handling Source Locations], as I was poking around in RdrHsSyn and found wondrous things like (dL->L wiz waz) all over the place.</div><div class=""><br class=""></div><div class="">General outline: <a href="https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow/HandlingSourceLocations" class="">https://ghc.haskell.org/trac/ghc/wiki/ImplementingTreesThatGrow/HandlingSourceLocations</a></div><div class="">Phab diff: <a href="https://phabricator.haskell.org/D5036" class="">https://phabricator.haskell.org/D5036</a></div><div class="">Trac ticket: <a href="https://ghc.haskell.org/trac/ghc/ticket/15495" class="">https://ghc.haskell.org/trac/ghc/ticket/15495</a></div><div class="">Commit: <a href="https://gitlab.haskell.org/ghc/ghc/commit/509d5be69c7507ba5d0a5f39ffd1613a59e73eea" class="">https://gitlab.haskell.org/ghc/ghc/commit/509d5be69c7507ba5d0a5f39ffd1613a59e73eea</a></div><div class=""><br class=""></div><div class="">I see why this change is wanted and how the new version works.</div><div class=""><br class=""></div><div class="">It seems to me, though, that this move makes us *less typed*. That is, it would be very easy (and disastrous) to forget to match on a location node. For example, I can now do this:</div><div class=""><br class=""></div><div class="">> foo :: LPat p -> ...</div><div class="">> foo (VarPat ...) = ...</div><div class=""><br class=""></div><div class="">Note that I have declared that foo takes a located pat, but then I forgot to extract the location with dL. This would type-check, but it would fail. Previously, the type checker would ensure that I didn't forget to match on the L constructor. This error would get caught after some poking about, because foo just wouldn't work.</div><div class=""><br class=""></div><div class="">However, worse, we might forget to *add* a location when downstream functions expect one. This would be harder to detect, for two reasons:</div><div class="">1. The problem is caught at deconstruction, and figuring out where an object was constructed can be quite hard.</div><div class="">2. The problem might silently cause trouble, because dL won't actually fail on a node missing a location -- it just gives noSrcSpan. So the problem would manifest as a subtle degradation in the quality of an error message, perhaps not caught until several patches (or years!) later.</div><div class=""><br class=""></div><div class="">So I'm uncomfortable with this direction of travel.</div><div class=""><br class=""></div><div class="">Has this aspect of this design been brought up before? I have to say I don't have a great solution to suggest. Perhaps the best I can think of is to make Located a type family. It would branch on the type index to HsSyn types, introducing a Located node for GhcPass but not for other types. This Isn't really all that extensible (I think) and it gives special status to GHC's usage of the AST. But it seems to solve the immediate problems without the downside above.</div><div class=""><br class=""></div><div class="">Sorry for reopening something that has already been debated, but (unless I'm missing something) the current state of affairs seems like a potential wellspring of subtle bugs.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Richard</div></body></html>