HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

ModuleCabal-syntax-3.12.1.0Haskell2010

Distribution.Compat.Newtype

Per Conor McBride, the Newtype typeclass represents the packing and unpacking of a newtype, and allows you to operate under that newtype with functions such as ala.

  • 1 class
  • 4 values
classclass 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 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.

Methods

Instances20Newtype, …
valueala
  1. :: (Newtype o n, Newtype o' n')
  2. => o -> n
  3. -> (o -> n) -> b -> n'
  4. -> b
  5. -> o'
#
Example1 expression
ala Sum foldMap [1, 2, 3, 4 :: Int]10

Note: the user supplied function for the newtype is ignored.

Example1 expression
ala (Sum . (+1)) foldMap [1, 2, 3, 4 :: Int]10
valuealaf
  1. :: (Newtype o n, Newtype o' n')
  2. => o -> n
  3. -> (a -> n) -> b -> n'
  4. -> a -> o
  5. -> b
  6. -> o'
#
Example1 expression
alaf Sum foldMap length ["cabal", "install"]12

Note: as with ala, the user supplied function for the newtype is ignored.

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

Variant of pack, which takes a phantom type.