Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class Newtype o n | n -> o where
- ala :: ( Newtype o n, Newtype o' n') => (o -> n) -> ((o -> n) -> b -> n') -> b -> o'
- alaf :: ( Newtype o n, Newtype o' n') => (o -> n) -> ((a -> n) -> b -> n') -> (a -> o) -> b -> o'
- pack' :: Newtype o n => (o -> n) -> o -> n
- unpack' :: Newtype o n => (o -> n) -> n -> o
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.
Nothing
Instances
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