Proposal: GHC.Generics marked UNSAFE for SafeHaskell

John Lato jwlato
Mon Oct 7 06:53:36 UTC 2013


Andres is right that it's not as evil as defining your own Typeable.  The
crux of the matter is that Generic essentially allows full access to the
data type.  Unfortunately it's easy to forget this...


On Mon, Oct 7, 2013 at 1:43 AM, Andres L?h <andres at well-typed.com> wrote:

> While I understand you all feel uncomfortable with this, I do not
> think the problem demonstrated by John has anything to do with
> Generic.
>
> I've made a fork here
>
> https://github.com/kosmikus/safe-bugtest
>
> that shows an (IMHO) similar problem using Show and Read instead of
> Generic. (And something slightly different could certainly also
> produced using Enum).
>
> If you're deriving Generic, then yes, you gain the functionality of
> that class, which is to inspect the structure of the type, and then
> yes, you can in principle construct any value of that type. So
> deriving Generic for types that should be abstract is always going to
> be risky. But this is no different than deriving any other class, only
> that Generic gives you particularly fine-grained access to the
> internals of a type.
>
> Also, at least in my opinion, it is entirely valid to define your own
> Generic instances. It's more work, and while I haven't used it often
> so far, I can imagine that there are good use cases. I don't think
> it's anywhere near as evil as defining your own Typeable instances.
>
> Cheers,
>   Andres
>
> --
> Andres L?h, Haskell Consultant
> Well-Typed LLP, http://www.well-typed.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20131007/6764b11c/attachment.html>




More information about the Libraries mailing list