Proposal: GHC.Generics marked UNSAFE for SafeHaskell
Andres Löh
andres
Mon Oct 7 06:43:00 UTC 2013
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
More information about the Libraries
mailing list