Spec-Zone.ru › Haskell 9

6.6. Deriving mechanism

Haskell 98 allows the programmer to add a deriving clause to a data type declaration, to generate a standard instance declaration for specified class. GHC extends this mechanism along several axes:

  • The derivation mechanism can be used separately from the data type declaration, using the standalone deriving mechanism.
  • In Haskell 98, the only derivable classes are Eq, Ord, Enum, Ix, Bounded, Read, and Show. Various language extensions extend this list.
  • Besides the stock approach to deriving instances by generating all method definitions, GHC supports two additional deriving strategies, which can derive arbitrary classes:

    • Generalised newtype deriving for newtypes and
    • deriving any class using an empty instance declaration.

    The user can optionally declare the desired deriving strategy, especially if the compiler chooses the wrong one by default.

  • 6.6.1. Deriving instances for empty data types
  • 6.6.2. Inferred context for deriving clauses
  • 6.6.3. Stand-alone deriving declarations
  • 6.6.4. Deriving instances of extra classes (Data, etc.)
  • 6.6.5. Generalised derived instances for newtypes
  • 6.6.6. Deriving any other class
  • 6.6.7. Deriving strategies
  • 6.6.8. Deriving via

© 2002–2007 The University Court of the University of Glasgow. All rights reserved.
Licensed under the Glasgow Haskell Compiler License.
https://downloads.haskell.org/~ghc/9.14.1/docs/users_guide/exts/deriving.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API