one-liner-instances: Generics-based implementations for common typeclasses

[ bsd3, library, web ] [ Propose Tags ]
This version is deprecated.

Provides generics-based implementations for common typeclasses using Generics. For now, has implementations for Numeric typeclasses (Num, Fractional, and Floating) and Semigroup and Monoid.

Please see the README on Github at https://github.com/mstksg/one-liner-instances#readme


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.1.0, 0.1.2.0, 0.1.2.1, 0.1.3.0 (info)
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5), one-liner (>=0.9) [details]
License BSD-3-Clause
Copyright (c) Justin Le 2018
Author Justin Le
Maintainer justin@jle.im
Category Web
Home page https://github.com/mstksg/one-liner-instances#readme
Bug tracker https://github.com/mstksg/one-liner-instances/issues
Source repo head: git clone https://github.com/mstksg/one-liner-instances
Uploaded by jle at 2018-02-03T21:57:43Z
Distributions LTSHaskell:0.1.3.0, NixOS:0.1.3.0, Stackage:0.1.3.0
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 2271 total (23 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-02-03 [all 1 reports]

Readme for one-liner-instances-0.1.0.0

[back to package description]

one-liner-instances

This package uses machinery from one-liner in order to provide default implementations for methods from Num, Fractional, Floating, Semigroup, and Monoid. These will work for any types (deriving Generic) that are made with one constructor, whose fields are all instances of that typeclass.

So, gPlus (generic addition) will work for:

data Tup1 a b = Tup1 a b            -- requires Num a, Num b
data Tup2 a   = Tup2 Int a          -- requires Num a, Num b
data Tup3     = Tup3 Int Double
data Tup4 a b = Tup4 Int Double     -- no constraint on a or b

But not on:

data Tup5 a   = Tup2 String a       -- String is not an instance of Num

These are implemented by applying the operation to every field.

Newtype wrappers

Similar to WrappedMonoid and WarppedMonad from base, some convenient newtype wrappers are provided that will give free instances of Num, etc. for appropriate types:

If a is a data type (deriving Generic) with a single constructor whose fields all have instances of Num, then GNum a has a Num instance (and same for Fractional, Floating, etc.).

If a is a data type (deriving Generic) with a single constructor whose fields all have instances of Semigroup, then GMonoid a has a Semigroup instance (and same for Monoid).