The data-default-extra package

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain]

An alternative to data-default package, that provides a lot of additional instances for Default type class.

Default type class provides a default value (def) of a type. In case when a particluar type has an instance for Monoid, then the default value should be mempty, otherwise it can cause a great deal of confusion.

One must understand, that Default type class, has no axioms associated with it. Its purpose is to minimize:

As one may notice, most of the listed problems, that Default type class tries to solve, to various degrees of success, are for human benefit, and not theoretically founded. Because of this, please always try hard to define sensible instances of Default. Most importantly, document what def means for particular type, and always check that def is sensible, by testing it on a real world sample of human beings, one is not a big enough sample.

That said, using Default may not always be a good idea. If it breaks people's mental model, or theoretical models with real axioms, then just don't use it.


[Skip to ReadMe]

Properties

Versions0.0.1, 0.1.0, 0.1.0
Change logChangeLog.md
Dependenciesbase (<6), data-default-class (>=0.0.1 && <0.2), data-default-instances-bytestring (==0.0.*), data-default-instances-case-insensitive (==0.0.*), data-default-instances-containers (==0.0.*), data-default-instances-dlist (==0.0.*), data-default-instances-new-base (>=0.0.1 && <0.2), data-default-instances-old-locale (==0.0.*), data-default-instances-text (==0.0.*), data-default-instances-unordered-containers (==0.0.*), data-default-instances-vector (==0.0.*), ghc-prim [details]
LicenseBSD3
Copyright(c) 2016-2017 Peter Trško
AuthorPeter Trško
Maintainerpeter.trsko@gmail.com
CategoryData
Home pagehttps://github.com/trskop/data-default-extra
Bug trackerhttps://github.com/trskop/data-default-extra/issues
Source repositoryhead: git clone git://github.com/trskop/data-default-extra.git
this: git clone git://github.com/trskop/data-default-extra.git(tag class-0.1.2)
UploadedThu Jan 5 22:21:37 UTC 2017 by PeterTrsko

Modules

[Index]

Flags

NameDescriptionDefaultType
with-bytestring

Provide instances for (lazy and strict) ByteString, ByteString Builder and for ShortByteString.

EnabledAutomatic
with-case-insensitive

Provide instance for CI (Case Insensitive) type wrapper.

EnabledAutomatic
with-containers

Provide instances for Set, Map, IntMap, IntSet, Seq, and Tree.

EnabledAutomatic
with-dlist

Provide instance for DList type.

DisabledAutomatic
with-text

Provide instance for (strict and lazy) Text and Text Builder.

EnabledAutomatic
with-old-locale

Provide instance for TimeLocale type.

EnabledAutomatic
with-unordered-containers

Provide instances for HashMap and HashSet.

EnabledAutomatic
with-vector

Provide instances for various (boxed and unboxed) Vector types.

EnabledAutomatic

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainers' corner

For package maintainers and hackage trustees


Readme for data-default-extra-0.1.0

[back to package description]

data-default-extra

Hackage Hackage Dependencies Haskell Programming Language BSD3 License

Build

Description

An alternative to data-default package, but built on top of the same underlying package data-default-class. This package provides a lot of additional instances for Default type class.

Default type class provides a default value (def) of a type. In case when a particluar type has an instance for Monoid, then the default value should be mempty, otherwise it can cause a great deal of confusion.

One must understand, that Default type class, has no axioms associated with it. Its purpose is to minimize:

As one may notice, most of the listed problems, that Default type class tries to solve, to various degrees of success, are for human benefit, and not theoretically founded. Because of this, please always try hard to define sensible instances of Default. Most importantly, document what def means for particular type, and always check that def is sensible, by testing it on a real world sample of human beings, one is not a big enough sample.

That said, using Default may not always be a good idea. If it breaks people's mental models, or theoretical models with real axioms, then just don't use it.

This package, in most part, just reexports a set of packages that provide additional instances for data-default-class package.

GHC Generics

Create Default instances using GHC Generics.

Usage example:

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DefaultSignatures #-}

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

data MyType = MyType Int (Maybe String)
  deriving (Generic, Show)

instance Default MyType
λ> def :: MyType
MyType 0 Nothing

One can also use DeriveAnyClass language extension:

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}

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

data MyType = MyType Int (Maybe String)
  deriving (Default, Generic, Show)

Be aware that DeriveAnyClass doesn't work well together with GeneralizedNewtypeDeriving on some versions of GHC. See GHC issue #10598

License

The BSD 3-Clause License, see LICENSE file for details.

Contributions

Contributions, pull requests and bug reports are welcome! Please don't be afraid to contact author using GitHub or by e-mail.