Use of language extensions

From HaskellWiki
Revision as of 05:21, 12 July 2021 by Atravers (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Haskell compilers are full of experimental features. However, when it comes to designing libraries one should carefully think about which extensions to use and which not. Every required language extension and every imported library which on its own depends on such an extension, causes some of the following problems:

  • The use of a language extension might indicate a design flaw! Sometimes you write an incorrect program and the compiler suggests to use a language extension to resolve that. It is a quick fix to solve the problem by enabling the extension, but if you do not understand the implications, you run into problems later. See e.g. List instance, Overlapping instance.
  • It limits the range of Haskell compilers you can use.
  • According to the availability of compilers on different platforms, it will also limit the range of machines it can be run on.
  • It complicates the installation, if a user has to install a particular compiler to use your library.
  • Many extensions are complicated enough to produce even more incomprehensible error messages, than errorneous Haskell 98 programs.
  • Even with the same compiler, in a year or two your code might need fixing if the extension or implementation is sufficiently experimental (for example, the rules for what type-signatures GADTs require, has changed from GHC 6.4 to 6.6 to 6.8 to 6.10). People who depend on your library may be impatient to upgrade to the newest version of GHC.

We suggest the following hierarchy of complexity with respect to types:

We recommend to explicitly switch on language extensions that are needed using the LANGUAGE pragma instead of switching them on all at once using the -fglasgow-exts compiler flag.

See also