<div dir="ltr"><div>In this thread, I am going to raise a topic for discussion. Please share your opinions and related experiences.</div><div><br></div><div>Evaluation of type families within HsSyn ASTs, such as `<font face="monospace, monospace">PostTc</font>`, with a fixed phase index, such as `<font face="monospace, monospace">GhcPs</font>`, gives us distinct ASTs at the *compile-time*.<br></div><div>However, when programming with these ASTs, we use patterns, such as `<font face="monospace, monospace">HsMultiIf :: PostTc p Type -> [LGRHS p (LHsExpr p)] -> HsExpr p</font>` that are shared among phases.</div><div>We can </div><div>(1) introduce a layer of abstraction providing a set of type and pattern synonyms specific to each phase, such as `<font face="monospace, monospace">PsMultiIf :: [LPsGRHS  LPsExpr] -> PsExpr</font>`; and</div><div>(2) updating code working on ASTs of specific phase to use the interface specific to the phase, such as by changing prefixes from `Hs` to `Ps` and by removing unused variables and placeholders; and</div><div>(3) leaving untouched code working uniformly on ASTs of different phases (i.e., the generic functions in Trees that Grow terminology), such as the existing functions whose types are polymorphic on phase index. </div><div><br></div><div>Some comments:</div><div><br></div><div>- It can be done gradually and smoothly: we add three separate files in HsSyn (per each phase) containing the phase-specific interfaces, and gradually import them and do the changes per module.</div><div>- Using the interfaces is optional: code using the current method (e.g., using `<font face="monospace, monospace">HsMultiIf</font>`) should work just fine.</div><div>- It introduces a layer of indirection and three more files to maintain. </div><div>- It makes code working on HsSyn ASTs, such as the renamer, appear cleaner as placeholders and similar machinery are abstracted away by the interfaces (e.g., no need to import bits and pieces of `<font face="monospace, monospace">HsExtension</font>`)</div><div>- In theory, there should be zero impact on GHC's runtime performance. </div><div><br></div><div>I am myself undecided about its benefit-cost ratio, but willing to at least implement the phase-specific interfaces.</div><div>For me, abstracting away all the `PostRn` stuff, `Out` prefixed constructors, and dummy placeholders from the front-end code is the most valuable.</div><div><br></div><div>Yours, </div><div>  Shayan</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br><div> </div></div></div>