newtype-generics: A typeclass and set of functions for working with newtypes, with generics support.

[ bsd3, control, library ] [ Propose Tags ]

Per Conor McBride, the Newtype typeclass represents the packing and unpacking of a newtype, and allows you to operatate under that newtype with functions such as ala. Generics support was added in version 0.4, making this package a full replacement for the original newtype package, and a better alternative to newtype-th.


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.4, 0.4.0.1, 0.4.1, 0.4.2, 0.5, 0.5.0.1, 0.5.1, 0.5.2, 0.5.2.1, 0.5.2.2, 0.5.3, 0.5.4, 0.6, 0.6.1, 0.6.2
Change log CHANGELOG.md
Dependencies base (>=4.6 && <4.11) [details]
License BSD-3-Clause
Author Darius Jahandarie, Conor McBride, João Cristóvão
Maintainer Simon Jakobi <simon.jakobi@gmail.com>
Category Control
Source repo head: git clone https://github.com/jcristovao/newtype-generics
Uploaded by sjakobi at 2017-08-16T18:54:43Z
Distributions Arch:0.6.2, Debian:0.5.4, Fedora:0.6.2, LTSHaskell:0.6.2, NixOS:0.6.2
Reverse Dependencies 17 direct, 8191 indirect [details]
Downloads 38196 total (235 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-08-16 [all 1 reports]

Readme for newtype-generics-0.5.0.1

[back to package description]

newtype-generics

A typeclass and set of functions for working with newtypes. Fork of the code published by Darius Jahandarie here, with the addition of generics.

The 'Newtype' typeclass and related functions: op, ala, ala', under. Primarly pulled from Conor McBride's Epigram work. Some examples:

-- foldMaps the list ala the Sum newtype. This results in 10.
ala Sum foldMap [1,2,3,4] 

-- foldMaps the list ala the Product newtype. This results in 24.
ala Product foldMap [1,2,3,4] 

-- foldMaps the list ala the Endo newtype. This results in 8.
ala Endo foldMap [(+1), (+2), (subtract 1), (*2)] 3 

NB: Data.Foldable.foldMap is a generalized mconcatMap which is a generalized concatMap.

This package includes Newtype instances for all the (non-GHC/foreign) newtypes in base (as seen in the examples). However, there are neat things you can do with this with /any/ newtype and you should definitely define your own 'Newtype' instances for the power of this library. For example, see ala Cont traverse, with the proper Newtype instance for Cont.

This could of course be eased with the addition of generics for version 0.3:

{-# LANGUAGE DeriveGeneric              #-}

import GHC.Generics
(...)
newtype Example = Example Int (deriving Generic)
instance Newtype Example