Datatype contexts

Contents
  • Data declaration context
  • A problem
  • One solution

The Haskell language standards, both Haskell98 and Haskell2010, allow datatypes to have contexts.The Haskell report shows which topdecls allow contexts That is, you are allowed to place constraints on type parameters as part of a data or newtype declaration. This was widely considered a useless feature, and so it is disabled by default in GHC. As of GHC 7.2, the feature is deprecated but can still be turned on, if desired, with a language extension called DatatypeContexts.The GHC User Guide on the DatatypeContexts extension.

The next language standard is expected to remove support for this feature.The Haskell Prime proposal to remove datatype contexts from the next standard.

Sign up for access to the full page, plus the complete archive and all the latest content.