Cabal is giving me mixed messages. When I say:
Extensions: DeriveFunctor
It says:
Warning: Unknown extensions: DeriveFunctor
But when I say:
GHC-Options: -XDeriveFunctor
It says:
Warning: Instead of 'ghc-options: -XDeriveFunctor' use 'extensions:
DeriveFunctor'
For now I'm just going to use the {-# LANGUAGE DeriveFunctor #-}
pragma.
$ cabal --version
cabal-install version 0.8.2
using version 1.8.0.6 of the Cabal library
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.12.3
$ basename $(mdfind haskell-platform | grep .dmg)
haskell-platform-2010.2.0.0.i386.dmg
You can still use extensions: DeriveFunctor
in your .cabal file. Yes, it is not an extension that is currently known to Cabal, but you can still use it and as long as the compiler recognises it then it will work. Indeed Cabal will check that the compiler does recognise the extension, even though Cabal does not itself know about it.
There is a central registry of extensions in the module Language.Haskell.Extension
. The purpose of this registry is so that different compilers can agree on the same names when they implement the same extensions. We have had cases in the past where authors of different compilers have accidentally given different names to the same extension concept. Not all extensions need to be registered. It makes sense not to register extensions that are still highly experimental, for example the DPH extensions "PArr" is still not registered. Hackage requires all uploaded packages to use only known registered extensions, which makes sense since if an extension is sufficiently ready to be used in a distributed package, then it is ok to register.
In this particular case, the GHC devs appear to have forgotten to register the extension.
It is also worth noting that as of Cabal-1.10 the extensions
field is being split into two: default-extensions
and other-extensions
. This addresses the issue that John points out in his answer, that the previous behaviour is that all extensions are active for all modules, which we acknowledge is a mistake. The other-extensions
field allows the extensions used in some modules (i.e. with the LANGUAGE
pragma) to be listed. Cabal will eventually enforce that they are all listed, just like it requires that all package dependencies are listed. Language dependencies are dependencies too.
According to the Hackage documentation, as of Cabal-1.8.0.6 DeriveFunctor
is not recognized. It's a relatively new addition to GHC and it doesn't seem to have wide use, so I'm not surprised it would have been overlooked for Cabal. This should probably be filed as a bug (feature request?) against Cabal.
@Tom Lokhorst is right that a LANGUAGE pragma is the best option. I don't like using Cabal's Extensions field because then all extensions are active for all modules, which I often don't want.
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