<div dir="ltr"><div>I have been updating the ghc-exactprint library for real world use cases on the about to be released GHC 9.2.1, and realised I need to be able to put an Anchor into every SrcSpan in the ParsedSource AST.</div><div><br></div><div>I prepared !6854 to sort it out in master and turned to the problem of GHC 9.2.1, where I had missed the boat.</div><div><br></div><div>And then I discovered that we have SrcSpan defined as</div><div><br></div><div>    data SrcSpan =<br>        RealSrcSpan !RealSrcSpan !(Maybe BufSpan)<br>      | UnhelpfulSpan !UnhelpfulSpanReason</div><div><br></div><div>and the (Maybe BufSpan) is only used for attaching haddock comments after parsing.</div><div><br></div><div>This means there is an isomorphism between the RealSrcSpan variant and an Anchor, which I take advantage of with the code in [1], by using the Maybe to encode the AnchorOperation and the BufSpan to encode the DeltaPos.</div><div><br></div><div>And it struck me that perhaps we should make this a more official approach.  The only problem is the detail of the BufSpan, to be able to play both roles cleanly.<br></div><div><br></div><div>Alan<br></div><div><br></div><div>[1] <a href="https://gist.github.com/alanz/5e262599ab79138606cdfcf3792ef635">https://gist.github.com/alanz/5e262599ab79138606cdfcf3792ef635</a></div><div><br></div><div><br></div></div>