<div dir="ltr"><div><div><div>And to answer my own question, it seems<br><br><font size="2"><span style="font-family:monospace,monospace">instance HasSourceText SourceText where<br>  noSourceText    = NoSourceText<br>  sourceText s    = SourceText s<br></span>     getSourceText a = a<br></font><br><br></div>And then applying the appropriate constraint at the use-site does the job.<br><br></div>So<br><br><span style="font-family:monospace,monospace">noSyntaxExpr :: (HasSourceText (XHsString x)) => SyntaxExpr x id</span><br><br></div>Alan<br><div><br><div><div><div><br></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 18 May 2017 at 09:04, Alan & Kim Zimmerman <span dir="ltr"><<a href="mailto:alan.zimm@gmail.com" target="_blank">alan.zimm@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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:<wbr>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" target="_blank">https://github.com/alanz/ghc/<wbr>blob/<wbr>df1c3b3d42284dd121086e6c571793<wbr>f19e758977/compiler/hsSyn/<wbr>HsExtension.hs#L73</a><br><br></div></div></div></div>
</blockquote></div><br></div>