Cabal-2.2.0.0: 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 #

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 #

unpack :: n -> o #

Instances

Newtype FilePathNT String # 
Newtype FreeText String # 
Newtype Token' String # 

Methods

pack :: String -> Token' #

unpack :: Token' -> String #

Newtype Token String # 

Methods

pack :: String -> Token #

unpack :: Token -> String #

Newtype TestedWith (CompilerFlavor, VersionRange) # 
Newtype SpecLicense (Either License License) # 
Newtype SpecVersion (Either Version VersionRange) # 
Newtype (Identity a) a # 

Methods

pack :: a -> Identity a #

unpack :: Identity a -> a #

Newtype (Sum a) a # 

Methods

pack :: a -> Sum a #

unpack :: Sum a -> a #

Newtype (Product a) a # 

Methods

pack :: a -> Product a #

unpack :: Product a -> a #

Newtype (MQuoted a) a # 

Methods

pack :: a -> MQuoted a #

unpack :: MQuoted a -> a #

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

Methods

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

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

Newtype (List sep wrapper a) [a] # 

Methods

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

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

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

>>> 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' #

>>> 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 #

Variant of pack, which takes a phantom type.

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

Variant of pack, which takes a phantom type.