Skip to content
A class for types with a default value
Haskell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/Data/Default
test
.gitignore
LICENSE
Makefile
README.md
Setup.lhs
data-default-generics.cabal

README.md

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.

You can’t perform that action at this time.