data-default-extra-0.1.0: A class for types with a default value.

Copyright(c) 2016-2017 Peter Trško
LicenseBSD3
Maintainerpeter.trsko@gmail.com
Stabilitystable
PortabilityGHC specific language extension.
Safe HaskellSafe
LanguageHaskell2010

Data.Default.Generic

Description

Deprecated: Use DefaultSignatures or DeriveAnyClass language extension instead.

DEPRECATED because package data-default-class now supports GHC Generics.

Create Default instances using GHC Generics. For more information see:

Package data-default-class supports GHC Generics since version 0.1.0, but it is still useful to have GDefault and genericDef exposed for more complex cases.

Synopsis

Documentation

Rule of thumb, if generic instance definition, contains more code then the explicit definition, then use the explicit definition.

Note, that sum types aren't supported, but even if they were, it is always better to explicitly specify Default instance for sum types.

Usage example:

{-# LANGUAGE DeriveGeneric #-}

import GHC.Generics (Generic)


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

instance Default MyType where
    def = genericDef
>>> def :: MyType
MyType 0 Nothing

genericDef :: (Generic a, GDefault (Rep a)) => a Source #

Derive implementation of def by using GHC Generics.

class GDefault f where Source #

Simple derivation of def definition that handles only product types, but not sum types. In case of sum types it is better to provide hand written instances for Default.

Minimal complete definition

gdef

Methods

gdef :: f a Source #

Instances

GDefault U1 Source # 

Methods

gdef :: U1 a Source #

Default a => GDefault (K1 i a) Source # 

Methods

gdef :: K1 i a a Source #

(GDefault a, GDefault b) => GDefault ((:*:) a b) Source # 

Methods

gdef :: (a :*: b) a Source #

GDefault a => GDefault (M1 i c a) Source # 

Methods

gdef :: M1 i c a a Source #