To use a language extension such as UnicodeSyntax
in all files of a project, 2 options are:
{-# LANGUAGE UnicodeSyntax #-}
extensions: UnicodeSyntax
in every section (library, executable, test) of the .cabal
file.Are there any reasons or best practices to choose one over the other?
I'm using stack
and their standard new-template
for simple packages.
The LANGUAGE pragma allows language extensions to be enabled in a portable way. It is the intention that all Haskell compilers support the LANGUAGE pragma with the same syntax, although not all extensions are supported by all compilers, of course. The LANGUAGE pragma should be used instead of OPTIONS_GHC , if possible.
Language extensions are used to enable language features in Haskell that may seem useful in certain cases. They can be used to loosen restrictions in the type system or add completely new language constructs to Haskell. or (in GHC) using flags -X<Extension> .
You can enable an extension for a single file by placing {-# LANGUAGE ExtensionName #-} on its own line at or near the top of the file (anywhere before the module header, or before the first import or definition if there is no module header, should be fine).
Personally, I always list all the language extensions in each file that uses them. Then you can tell exactly what extensions a particular piece of code is using, just by looking at the code. That means I can instantly tell, for example, is this code doing something with Template Haskell or not. And I don't have to look at any related files to figure that out. It also means I can compile just that module, manually from the command line, without having to memorise which extensions I need.
I suppose there is something to be said for being able to glance at the Cabal spec to see which extensions a particular package uses.
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