Type families and classes
Alan & Kim Zimmerman
alan.zimm at gmail.com
Thu May 18 07:15:21 UTC 2017
And to answer my own question, it seems
instance HasSourceText SourceText where
noSourceText = NoSourceText
sourceText s = SourceText s
getSourceText a = a
And then applying the appropriate constraint at the use-site does the job.
So
noSyntaxExpr :: (HasSourceText (XHsString x)) => SyntaxExpr x id
Alan
On 18 May 2017 at 09:04, Alan & Kim Zimmerman <alan.zimm at gmail.com> wrote:
> Hi all
>
> 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.
>
> The specific case is to be able to contain a SourceText, in the context of
> HsLit
>
> So I have (stripped down)
>
> data GHCX
>
> type family XHsString x
>
> type instance XHsString GHCX = SourceText
>
> class HasSourceText a where
> -- Provide setters to mimic existing constructors
> noSourceText :: a
> sourceText :: String -> a
>
> getSourceText :: a -> SourceText
>
> instance HasSourceText (XHsString GHCX) where
> noSourceText = NoSourceText
> sourceText s = SourceText s
> getSourceText a = a
>
>
> But this gives an error
>
> compiler/hsSyn/HsExtension.hs:80:10: error:
> • Illegal type synonym family application in instance:
> XHsString GHCX
> • In the instance declaration for ‘HasSourceText (XHsString GHCX)’
>
> Is there some way to achieve this, or is it simply impossible?
>
> The full work-in-progress source is here[2]
>
> Regards
> Alan
>
>
> [1] https://arxiv.org/abs/1610.04799
> [2] https://github.com/alanz/ghc/blob/df1c3b3d42284dd121086e6c571793
> f19e758977/compiler/hsSyn/HsExtension.hs#L73
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20170518/f870ecc0/attachment.html>
More information about the ghc-devs
mailing list