Skip to content

jcristovao/data-default-generics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A class for types with a default value

Resources

License

Stars

Watchers

Forks

Packages

No packages published