Cabal-2.4.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.

Methods

pack :: o -> n Source #

unpack :: n -> o Source #

Instances
Newtype FilePathNT String # 
Instance details

Defined in Distribution.Parsec.Newtypes

Newtype FreeText String # 
Instance details

Defined in Distribution.Parsec.Newtypes

Newtype Token' String # 
Instance details

Defined in Distribution.Parsec.Newtypes

Newtype Token String # 
Instance details

Defined in Distribution.Parsec.Newtypes

Newtype TestedWith (CompilerFlavor, VersionRange) # 
Instance details

Defined in Distribution.Parsec.Newtypes

Newtype SpecLicense (Either License License) # 
Instance details

Defined in Distribution.Parsec.Newtypes

Newtype SpecVersion (Either Version VersionRange) # 
Instance details

Defined in Distribution.Parsec.Newtypes

Newtype (Identity a) a # 
Instance details

Defined in Distribution.Compat.Newtype

Methods

pack :: a -> Identity a Source #

unpack :: Identity a -> a Source #

Newtype (Sum a) a # 
Instance details

Defined in Distribution.Compat.Newtype

Methods

pack :: a -> Sum a Source #

unpack :: Sum a -> a Source #

Newtype (Product a) a # 
Instance details

Defined in Distribution.Compat.Newtype

Methods

pack :: a -> Product a Source #

unpack :: Product a -> a Source #

Newtype (MQuoted a) a # 
Instance details

Defined in Distribution.Parsec.Newtypes

Methods

pack :: a -> MQuoted a Source #

unpack :: MQuoted a -> a Source #

Newtype (Endo a) (a -> a) # 
Instance details

Defined in Distribution.Compat.Newtype

Methods

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

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

Newtype (List sep wrapper a) [a] # 
Instance details

Defined in Distribution.Parsec.Newtypes

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.