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

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

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

unpack :: n -> o Source #

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

Instances

Instances details
Newtype String FilePathNT # 
Instance details

Defined in Distribution.Parsec.Newtypes

Newtype String Token' # 
Instance details

Defined in Distribution.Parsec.Newtypes

Newtype String Token # 
Instance details

Defined in Distribution.Parsec.Newtypes

Newtype a (Product a) # 
Instance details

Defined in Distribution.Compat.Newtype

Methods

pack :: a -> Product a Source #

unpack :: Product a -> a Source #

Newtype a (Sum a) # 
Instance details

Defined in Distribution.Compat.Newtype

Methods

pack :: a -> Sum a Source #

unpack :: Sum a -> a Source #

Newtype a (Identity a) # 
Instance details

Defined in Distribution.Compat.Newtype

Methods

pack :: a -> Identity a Source #

unpack :: Identity a -> a Source #

Newtype a (MQuoted a) # 
Instance details

Defined in Distribution.Parsec.Newtypes

Methods

pack :: a -> MQuoted a Source #

unpack :: MQuoted a -> a Source #

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

Defined in Distribution.Parsec.Newtypes

Methods

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

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

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

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

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

Variant of pack, which takes a phantom type.

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

Variant of pack, which takes a phantom type.