A class for types with a default value.

Latest on Hackage:0.1.0

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow to host generated Haddocks.

BSD3 licensed by Peter Trško
Maintained by


[Hackage][data-default-extra] Hackage Dependencies [Haskell Programming Language][] [BSD3 License][tl;dr Legal: BSD3]



An alternative to data-default package, but built on top of the same underlying package [data-default-class][]. This package provides a lot of additional instances for Default type class.

Default type class provides a default value (def) of a type. In case when a particluar type has an instance for Monoid, then the default value should be mempty, otherwise it can cause a great deal of confusion.

One must understand, that Default type class, has no axioms associated with it. Its purpose is to minimize:

  • Number of imports.

  • Number of introduced definitions that are part of an API.

  • Complexity of building more complicated "default values" out of simpler "default values".

  • Cognitive overhead. (Reduction of cognitive overhead is partially a consequence of reducing above issues.)

As one may notice, most of the listed problems, that Default type class tries to solve, to various degrees of success, are for human benefit, and not theoretically founded. Because of this, please always try hard to define sensible instances of Default. Most importantly, document what def means for particular type, and always check that def is sensible, by testing it on a real world sample of human beings, one is not a big enough sample.

That said, using Default may not always be a good idea. If it breaks people's mental models, or theoretical models with real axioms, then just don't use it.

This package, in most part, just reexports a set of packages that provide additional instances for [data-default-class][] package.

GHC Generics

Create Default instances using [GHC Generics][].

Usage example:

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DefaultSignatures #-}

import GHC.Generics (Generic)
import Data.Default (Default)

data MyType = MyType Int (Maybe String)
  deriving (Generic, Show)

instance Default MyType
λ> def :: MyType
MyType 0 Nothing

One can also use DeriveAnyClass language extension:

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}

import GHC.Generics (Generic)
import Data.Default (Default)

data MyType = MyType Int (Maybe String)
  deriving (Default, Generic, Show)

Be aware that DeriveAnyClass doesn't work well together with GeneralizedNewtypeDeriving on some versions of GHC. See [GHC issue #10598][]


The BSD 3-Clause License, see [LICENSE][] file for details.


Contributions, pull requests and bug reports are welcome! Please don't be afraid to contact author using GitHub or by e-mail. "Hackage: data-default" [data-default-class]: "Hackage: data-default-class" [data-default-extra]: "Package data-default-extra on Hackage" [GHC Generics]: "GHC.Generics on HaskellWiki" [GHC issue #10598]: "GHC issue #10598: DeriveAnyClass and GND don't work well together" []: "The Haskell Programming Language" [LICENSE]: "License of data-default-extra package." [tl;dr Legal: BSD3]: "BSD 3-Clause License (Revised)"


ChangeLog / ReleaseNotes

Version 0.0.1

Version 0.1.0

  • Support for data-default-class ==0.1.* and related instance modules.
  • Avoiding dependency on data-default-instances-base when building with data-default-class >=0.1.2.
  • Module Data.Default.Generic is now deprecated, since package data-default-class >=0.1 supports GHC Generics on its own. "HackageDB (or just Hackage) is a collection of releases of Haskell packages."

comments powered byDisqus