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

Copyright(c) 2016, Peter Trško
LicenseBSD3
Maintainerpeter.trsko@gmail.com
Stabilitystable
PortabilityFlexibleContexts, NoImplicitPrelude, TypeOperators
Safe HaskellSafe
LanguageHaskell2010

Data.Default.Generic

Description

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

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.

Methods

gdef :: f a Source

Instances