From the documentation I'm inclined to think that if I enable the DerivingStrategies extension, I don't need to enable GeneralizedNewtypeDeriving or DeriveAnyClass, nor any other extension that I currently listed right before §6.6.7.1, e.g. DerivingVia.
However, this toy example
{-# LANGUAGE DerivingStrategies #-}
newtype MyNum = MyNum Int
deriving stock (Eq, Ord, Show, Read)
deriving newtype (Num, Enum, Real, Integral)
main :: IO ()
main = print $ MyNum 0
compiles just fine via ghc this-file.hs (GHC 9.4.8), but it doesn't via cabal build (Cabal 3.10.2.1), because in the latter case, it is also required that I add
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
Any clue why is that?
The dummy foo.cabal file I'm using is
cabal-version: 3.8
name: foo
version: 1.0
executable foo
main-is: main.hs
build-depends: base
You do need to enable the individual extensions.
DerivingStrategiesonly gives you new syntax to specify which deriving strategy you want.The reason that GHC doesn't require you to enable
GeneralizedNewtypeDerivingis because it is part of theGHC2021language extension set and GHC uses the language extension setGHC2021by default.Cabal determines the language extension set it uses via the
default-languagefield of your components. In your example you have left it out (which is bad practice) and apparently Cabal still usesHaskell2010by default in that case. So, to fix this you can simply set thedefault-languagefield: