Cabal-3.0.0.0: A framework for packaging Haskell software

Safe HaskellNone
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 o n | n -> o where #

The FunctionalDependencies version of Newtype type-class.

Since Cabal-3.0 class arguments are in a different order than in newtype package. This change is to allow usage with DeriveAnyClass (and DerivingStrategies, in GHC-8.2). Unfortunately one have to repeat inner type.

newtype New = New Old
  deriving anyclass (Newtype Old)

Another approach would be to use TypeFamilies (and possibly compute inner type using GHC.Generics), but we think FunctionalDependencies version gives cleaner type signatures.

Minimal complete definition

Nothing

Methods

pack :: o -> n #

pack :: Coercible o n => o -> n #

unpack :: n -> o #

unpack :: Coercible n o => n -> o #

Instances
Newtype String FilePathNT # 
Instance details

Defined in Distribution.Parsec.Newtypes

Newtype String Token' # 
Instance details

Defined in Distribution.Parsec.Newtypes

Methods

pack :: String -> Token' #

unpack :: Token' -> String #

Newtype String Token # 
Instance details

Defined in Distribution.Parsec.Newtypes

Methods

pack :: String -> Token #

unpack :: Token -> String #

Newtype a (Product a) # 
Instance details

Defined in Distribution.Compat.Newtype

Methods

pack :: a -> Product a #

unpack :: Product a -> a #

Newtype a (Sum a) # 
Instance details

Defined in Distribution.Compat.Newtype

Methods

pack :: a -> Sum a #

unpack :: Sum a -> a #

Newtype a (Identity a) # 
Instance details

Defined in Distribution.Compat.Newtype

Methods

pack :: a -> Identity a #

unpack :: Identity a -> a #

Newtype a (MQuoted a) # 
Instance details

Defined in Distribution.Parsec.Newtypes

Methods

pack :: a -> MQuoted a #

unpack :: MQuoted a -> a #

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

Defined in Distribution.Parsec.Newtypes

Methods

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

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

Newtype (Either Version VersionRange) SpecVersion # 
Instance details

Defined in Distribution.Parsec.Newtypes

Newtype (Either License License) SpecLicense # 
Instance details

Defined in Distribution.Parsec.Newtypes

Newtype (CompilerFlavor, VersionRange) TestedWith # 
Instance details

Defined in Distribution.Parsec.Newtypes

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

Defined in Distribution.Compat.Newtype

Methods

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

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

ala :: (Newtype o n, Newtype o' n') => (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 o n, Newtype o' n') => (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 o n => (o -> n) -> o -> n #

Variant of pack, which takes a phantom type.

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

Variant of pack, which takes a phantom type.