Distribution.Compat.Newtype

Cabal-2.2.0.1: A framework for packaging Haskell software

Safe Haskell | Safe
Language | Haskell2010

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

- class Newtype n o | n -> o where
- ala :: (Newtype n o, Newtype n' o') => (o -> n) -> ((o -> n) -> b -> n') -> b -> o'
- alaf :: (Newtype n o, Newtype n' o') => (o -> n) -> ((a -> n) -> b -> n') -> (a -> o) -> b -> o'
- pack' :: Newtype n o => (o -> n) -> o -> n
- unpack' :: Newtype n o => (o -> n) -> n -> o

# 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 # |
Instance details Defined in Distribution.Parsec.Newtypes Methods pack :: String -> FilePathNT # unpack :: FilePathNT -> String #
Newtype FreeText String # |
Instance details Defined in Distribution.Parsec.Newtypes Methods pack :: String -> FreeText # unpack :: FreeText -> String #
Newtype Token' String # |
Instance details Defined in Distribution.Parsec.Newtypes Methods pack :: String -> Token' # unpack :: Token' -> String #
Newtype Token String # |
Instance details Defined in Distribution.Parsec.Newtypes Methods pack :: String -> Token # unpack :: Token -> String #
Newtype TestedWith (CompilerFlavor, VersionRange) # |
Instance details Defined in Distribution.Parsec.Newtypes Methods pack :: (CompilerFlavor, VersionRange) -> TestedWith # unpack :: TestedWith -> (CompilerFlavor, VersionRange) #
Newtype SpecLicense (Either License License) # |
Instance details Defined in Distribution.Parsec.Newtypes Methods pack :: Either License0 License -> SpecLicense # unpack :: SpecLicense -> Either License0 License #
Newtype SpecVersion (Either Version VersionRange) # |
Instance details Defined in Distribution.Parsec.Newtypes Methods pack :: Either Version VersionRange -> SpecVersion # unpack :: SpecVersion -> Either Version VersionRange #
Newtype (Identity a) a # |
Instance details Defined in Distribution.Compat.Newtype Methods pack :: a -> Identity a # unpack :: Identity a -> a #
Newtype (Sum a) a # |
Instance details Defined in Distribution.Compat.Newtype Methods pack :: a -> Sum a # unpack :: Sum a -> a #
Newtype (Product a) a # |
Instance details Defined in Distribution.Compat.Newtype Methods pack :: a -> Product a # unpack :: Product a -> a #
Newtype (MQuoted a) a # |
Instance details Defined in Distribution.Parsec.Newtypes Methods pack :: a -> MQuoted a # unpack :: MQuoted a -> a #
Newtype (Endo a) (a -> a) # |
Instance details Defined in Distribution.Compat.Newtype Methods pack :: (a -> a) -> Endo a # unpack :: Endo a -> a -> a #
Newtype (List sep wrapper a) [a] # |
Instance details Defined in Distribution.Parsec.Newtypes 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.