Cabal-3.6.0.0: A framework for packaging Haskell software
Safe HaskellSafe-Inferred
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 has 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 CabalSpecVersion SpecVersion Source # 
Instance details

Defined in Distribution.FieldGrammar.Newtypes

Newtype String FilePathNT Source # 
Instance details

Defined in Distribution.FieldGrammar.Newtypes

Newtype String Token Source # 
Instance details

Defined in Distribution.FieldGrammar.Newtypes

Newtype String Token' Source # 
Instance details

Defined in Distribution.FieldGrammar.Newtypes

Newtype a (MQuoted a) Source # 
Instance details

Defined in Distribution.FieldGrammar.Newtypes

Methods

pack :: a -> MQuoted a Source #

unpack :: MQuoted a -> a Source #

Newtype a (Identity a) Source # 
Instance details

Defined in Distribution.Compat.Newtype

Methods

pack :: a -> Identity a Source #

unpack :: Identity a -> a Source #

Newtype a (Product a) Source # 
Instance details

Defined in Distribution.Compat.Newtype

Methods

pack :: a -> Product a Source #

unpack :: Product a -> a Source #

Newtype a (Sum a) Source # 
Instance details

Defined in Distribution.Compat.Newtype

Methods

pack :: a -> Sum a Source #

unpack :: Sum a -> a Source #

Newtype (NonEmpty a) (NonEmpty' sep wrapper a) Source # 
Instance details

Defined in Distribution.FieldGrammar.Newtypes

Methods

pack :: NonEmpty a -> NonEmpty' sep wrapper a Source #

unpack :: NonEmpty' sep wrapper a -> NonEmpty a Source #

Newtype (Set a) (Set' sep wrapper a) Source # 
Instance details

Defined in Distribution.FieldGrammar.Newtypes

Methods

pack :: Set a -> Set' sep wrapper a Source #

unpack :: Set' sep wrapper a -> Set a Source #

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

Defined in Distribution.FieldGrammar.Newtypes

Methods

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

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

Newtype (Either License License) SpecLicense Source # 
Instance details

Defined in Distribution.FieldGrammar.Newtypes

Newtype (CompilerFlavor, VersionRange) TestedWith Source # 
Instance details

Defined in Distribution.FieldGrammar.Newtypes

Newtype (a -> a) (Endo a) Source # 
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 unpack, which takes a phantom type.