Cabal-2.2.0.1: A framework for packaging Haskell software

Safe HaskellSafe
LanguageHaskell2010

Distribution.Compat.Newtype

Description

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.

Synopsis

Documentation

class Newtype n o | n -> o where Source #

The FunctionalDependencies version of Newtype type-class.

Note: for actual newtypes the implementation can be pack = coerce; unpack = coerce. We don't have default implementation, because Cabal have to support older than base >= 4.7 compilers. Also, Newtype could witness a non-structural isomorphism.

Minimal complete definition

pack, unpack

Methods

pack :: o -> n Source #

unpack :: n -> o Source #

Instances

Newtype FilePathNT String Source # 
Newtype FreeText String Source # 
Newtype Token' String Source # 
Newtype Token String Source # 
Newtype TestedWith (CompilerFlavor, VersionRange) Source # 
Newtype SpecLicense (Either License License) Source # 
Newtype SpecVersion (Either Version VersionRange) Source # 
Newtype (Identity a) a Source # 

Methods

pack :: a -> Identity a Source #

unpack :: Identity a -> a Source #

Newtype (Sum a) a Source # 

Methods

pack :: a -> Sum a Source #

unpack :: Sum a -> a Source #

Newtype (Product a) a Source # 

Methods

pack :: a -> Product a Source #

unpack :: Product a -> a Source #

Newtype (MQuoted a) a Source # 

Methods

pack :: a -> MQuoted a Source #

unpack :: MQuoted a -> a Source #

Newtype (Endo a) (a -> a) Source # 

Methods

pack :: (a -> a) -> Endo a Source #

unpack :: Endo a -> a -> a Source #

Newtype (List sep wrapper a) [a] Source # 

Methods

pack :: [a] -> List sep wrapper a Source #

unpack :: List sep wrapper a -> [a] Source #

ala :: (Newtype n o, Newtype n' o') => (o -> n) -> ((o -> n) -> b -> n') -> b -> o' Source #

>>> ala Sum foldMap [1, 2, 3, 4 :: Int]
10

Note: the user supplied function for the newtype is ignored.

>>> ala (Sum . (+1)) foldMap [1, 2, 3, 4 :: Int]
10

alaf :: (Newtype n o, Newtype n' o') => (o -> n) -> ((a -> n) -> b -> n') -> (a -> o) -> b -> o' Source #

>>> alaf Sum foldMap length ["cabal", "install"]
12

Note: as with ala, the user supplied function for the newtype is ignored.

pack' :: Newtype n o => (o -> n) -> o -> n Source #

Variant of pack, which takes a phantom type.

unpack' :: Newtype n o => (o -> n) -> n -> o Source #

Variant of pack, which takes a phantom type.