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

Modulerelude-1.2.0.0Haskell2010

Relude.Extra.Newtype

SPDX-License-Identifier : MIT Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable

Functions to ease work with newtypes.

  • 6 values
  • Packagerelude-1.2.0.0
  • Exports6
  • LanguageHaskell2010
  • LicenceMIT
  • SourceNewtype.hs
valueun :: Coercible a n => n -> a
#

Unwraps value from newtype.

Example3 expressions
newtype Size = Size Int deriving Showun @Int (Size 5)5un (Size 5) == length ['a', 'x', 'b']False
valuewrap :: Coercible a n => a -> n
#

Wraps value to newtype. Behaves exactly as un but has more meaningful name in case you need to convert some value to newtype.

Example2 expressions
newtype Flag = Flag Bool deriving (Show, Eq)wrap False == Flag TrueFalse
valueunder :: Coercible a n => (n -> n) -> a -> a
#

Applies function to the content of newtype. This function is not supposed to be used on newtypes that are created with the help of smart constructors.

Example4 expressions
newtype Foo = Foo Bool deriving Showunder not (Foo True)Foo Falsenewtype Bar = Bar String deriving Showunder (filter (== 'a')) (Bar "abacaba")Bar "aaaa"
valueunder2 :: Coercible a n => (n -> n -> n) -> a -> a -> a
#

Lift binary function for newtypes to work over underlying newtype representation.

Example2 expressions
under2 @(Sum Int) (<>) (3 :: Int) 47under2 @All (<>) True FalseFalse
valueunderF2 :: Coercible a (n a) => (n a -> n a -> n a) -> a -> a -> a
#

Version of under2 that works on newtypes parametrized by their representation. Provided for convenience.

Example2 expressions
underF2 @Sum (<>) (3 :: Int) 47underF2 @Max (<>) 'p' 't''t'
value(#.) :: Coercible b c => (b -> c) -> (a -> b) -> a -> c
#

Coercible composition. This function allows to write more efficient implementations of function compositions over newtypes.