Popularity
3.6
Declining
Activity
0.0
Stable
4
4
0

Monthly Downloads: 8
Programming language: Haskell
License: BSD 3-clause "New" or "Revised" License
Tags: Data    
Latest version: v0.5.1

data-default-generics alternatives and similar packages

Based on the "Data" category.
Alternatively, view data-default-generics alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of data-default-generics or a related project?

Add another 'Data' Package

README

data-default-generics

A class for types with a default value.

This is a fork of the package originally developed by Lukas Mai, data-default, with the following additions:

It should be usable as a drop-in replacement.

Usage

Supose you've got a structure:

data TestRec = TestRec
  { bool    :: Bool
  , txt     :: T.Text
  , bs      :: BSL.ByteString
  , lst     :: [CInt]
  , ut      :: UTCTime
  } deriving (Eq,Show)

And you want to quickly define a default value for it, in a way that does not require code changes if the structure later gets altered. Modify the previous to:

{-# LANGUAGE DeriveGeneric       #-} 

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

data TestRec = TestRec
  { bool    :: Bool
  , txt     :: T.Text
  , bs      :: BSL.ByteString
  , lst     :: [CInt]
  , ut      :: UTCTime
  } deriving (Eq,Show, Generic)

instance Default TestRec 

And then you can use the default value for this structure as def, as long as you import Data.Default.Generics.

Bugs

Issues and pull requests are most welcome. Any additional instance for data types from the Haskell Platform will be considered.