Copyright | (c) 2016, Peter Trško |
---|---|
License | BSD3 |
Maintainer | peter.trsko@gmail.com |
Stability | stable |
Portability | FlexibleContexts, NoImplicitPrelude, TypeOperators |
Safe Haskell | Safe |
Language | Haskell2010 |
Create Default
instances using GHC Generics. For more information see:
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.