I enabled the Safe extension, and now I have this warning:
<no location info>: warning: [GHC-98887]
-XGeneralizedNewtypeDeriving is not allowed in Safe Haskell; ignoring -XGeneralizedNewtypeDeriving
However, I don't use that in the first place.
Starting with GHC 9.2.1, the GHC2021 language variant was made the default. It enabled a large set of extensions, including GeneralizedNewtypeDeriving.
Since GeneralizedNewtypeDeriving conflicts with the Safe extension, if you enable Safe with these newer GHC versions then you get a warning and GeneralizedNewtypeDeriving ends up being disabled.
This was actually documented in the 9.2.1 release notes but disappeared in later version of the documentation. The advice given in the release notes is:
Because
GHC2021includesGeneralizedNewtypeDeriving, which is not safe for Safe Haskell, users of Safe Haskell are advised to useHaskell2010explicitly.
So, that's one solution for getting rid of the warning. You can compile with the GHC -XHaskell2010 flag, add a default-language: Haskell2010 clause to your .cabal file, or add a pragma at the top of your module, like so:
{-# LANGUAGE Haskell2010 #-}
{-# LANGUAGE Safe #-}
module Okay where
...
You can also take the more conservative approach of keeping the rest of GHC2021 but disabling GeneralizedNewtypeDeriving using:
{-# LANGUAGE Safe #-}
{-# LANGUAGE NoGeneralizedNewtypeDeriving #-}
module Unsafe where
...
The order of the two pragmas doesn't matter, so use whichever you prefer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With