Copyright | (c) 2016-2017 Peter Trško |
---|---|
License | BSD3 |
Maintainer | peter.trsko@gmail.com |
Stability | stable |
Portability | GHC specific language extension. |
Safe Haskell | Safe |
Language | Haskell2010 |
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.
- genericDef :: (Generic a, GDefault (Rep a)) => a
- class GDefault f where
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) instanceDefault
MyType wheredef
=genericDef
>>>
def :: MyType
MyType 0 Nothing
genericDef :: (Generic a, GDefault (Rep a)) => a Source #
Derive implementation of def
by using GHC Generics.