I have a Haskell project that regularly uses a lot of language features, and I want the language extension block for each source file to be the same. Here’s a list,
{-# LANGUAGE Arrows,
BangPatterns,
DefaultSignatures,
DeriveDataTypeable,
DeriveFunctor,
EmptyDataDecls,
FlexibleContexts,
FlexibleInstances,
FunctionalDependencies,
GADTs,
GeneralizedNewtypeDeriving,
MultiParamTypeClasses,
NamedFieldPuns,
NoImplicitPrelude,
NoMonomorphismRestriction,
OverlappingInstances,
RankNTypes,
RebindableSyntax,
ScopedTypeVariables,
StandaloneDeriving,
TemplateHaskell,
TypeFamilies,
TypeOperators,
TypeSynonymInstances,
UndecidableInstances,
ViewPatterns #-}
Maybe to some it’s bad practice, but I consider language extensions to be part of the “Haskell+” that I usually write code in. And, I want that to be the same across modules. For example, the NoImplicitPrelude changes the language dramatically, and I want it uniform for all modules.
Question: How can I achieve this, without copy-pasting the language block into each file? It gets annoying how I often learn a new language feature, add it to module A, then start working on module B, and realize I have to go copy the language block from module A.
Just FYI the CPP pragma with a #include does not do the trick! Thanks in advance.
Use cabal as your build system, and list the language extensions you want in the
Extensionsfield of theLibraryorExecutablesection of yourproject.cabalfile. Then remove theLANGUAGEblock from your Haskell source files.See the Cabal User Guide, including the third paragraph of the introduction.
Ghci is where it all falls down. There is talk of adding a
cabal ghcicommand, but in the meantime it’s a bit icky.If your project is a library, you can run
ghci -package-conf dist/package.conf.inplace.If you want to load unexposed modules in ghci, I’d define a “development mode” flag in your
project.cabal:…conditionally expose extra modules in development mode:
…and explicitly enable development mode when you run
cabal configure: