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 Extensions
field of the Library
or Executable
section of your project.cabal
file. Then remove the LANGUAGE
block 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 ghci
command, 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
:
Flag development
Description: Development mode: expose all modules, enable warnings.
Default: False
...conditionally expose extra modules in development mode:
Library
Exposed-modules: My.Module, My.Module.Extra
if flag(development)
Exposed-modules: My.Module.Hidden, My.Module.Secret
GHC-Options: -Wall
-- plus your extensions, etc
...and explicitly enable development mode when you run cabal configure
:
$ cabal configure -f development
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