[Haskell-cafe] Should circular deriving "via" be rejected?

David Feuer david.feuer at gmail.com
Fri Nov 12 18:57:52 UTC 2021


I think it would be good to raise an issue on the GHC GitLab. It would
obviously be a nice feature, and the GHC devs are best positioned to figure
out if it's worth the time and trouble. Any such check will surely be
imprecise, since deriving via instances can take lots of forms, but it'd be
nice to catch simple cases. Presumably it'd be a warning and not an error.

On Fri, Nov 12, 2021, 1:30 PM Viktor Dukhovni <ietf-dane at dukhovni.org>
wrote:

>
> GHC accepts:
>
>     {-# LANGUAGE DerivingStrategies, DerivingVia #-}
>     newtype Foo = Foo Int deriving (Show, Eq) via (Bar)
>     newtype Bar = Bar Int deriving (Show, Eq) via (Foo)
>
> should there be any effort to avoid circular definitions?
>
> Of course one could always implement an explicit `show` method that
> diverges, so perhaps this is no worse, but on the other hand, statically
> deciding divergence looks potentially easier in this case...  On the
> other hand actual definitions like this seem unlikely in practice, so
> perhaps not worth burning precious compiler cycles to detect them?
>
> --
>     Viktor.
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20211112/32c263f8/attachment.html>


More information about the Haskell-Cafe mailing list