<div dir="ltr"><div><div><div><div>Hi all<br><br></div>I am experimenting with Trees that Grow [1] in the context of the GHC HsSyn AST, and wanting to express that a given extension point needs to have certain properties.<br><br></div>The specific case is to be able to contain a SourceText, in the context of HsLit<br><br></div>So I have (stripped down)<br><br><font size="2"><span style="font-family:monospace,monospace">data GHCX<br><br>type family XHsString x<br><br>type instance XHsString GHCX = SourceText<br><br>class HasSourceText a where<br>  -- Provide setters to mimic existing constructors<br>  noSourceText  :: a<br>  sourceText    :: String -> a<br><br>  getSourceText :: a -> SourceText<br><br>instance HasSourceText (XHsString GHCX) where<br>  noSourceText    = NoSourceText<br>  sourceText s    = SourceText s<br></span>     getSourceText a = a<br></font><br><br></div>But this gives an error<br><br>compiler/hsSyn/HsExtension.hs:80:10: error:<br>    • Illegal type synonym family application in instance:<br>        XHsString GHCX<br>    • In the instance declaration for ‘HasSourceText (XHsString GHCX)’<br><br><div>Is there some way to achieve this, or is it simply impossible?<br><br></div><div>The full work-in-progress source is here[2]<br></div><div><br></div><div>Regards<br></div><div>  Alan<br></div><div><div><br><div><br>[1] <a href="https://arxiv.org/abs/1610.04799" target="_blank">https://arxiv.org/abs/1610.047<wbr>99</a><br>[2] <a href="https://github.com/alanz/ghc/blob/df1c3b3d42284dd121086e6c571793f19e758977/compiler/hsSyn/HsExtension.hs#L73">https://github.com/alanz/ghc/blob/df1c3b3d42284dd121086e6c571793f19e758977/compiler/hsSyn/HsExtension.hs#L73</a><br><br></div></div></div></div>