Copyright | (c) 2015, Peter Trško |
---|---|
License | BSD3 |
Maintainer | peter.trsko@gmail.com |
Stability | experimental |
Portability | NoImplicitPrelude |
Safe Haskell | Safe |
Language | Haskell2010 |
Convert endomorphism in to a value.
- class FromEndo a where
- type EndoOperatedOn a
- fromEndo :: Endo (EndoOperatedOn a) -> a
- fromDualEndo :: Dual (Endo (EndoOperatedOn a)) -> a
- fromEndoWith :: (FromEndo a, EndoOperatedOn a ~ c) => (a -> b) -> Endo c -> b
- fromEndoWithF :: (Functor f, FromEndo a, EndoOperatedOn a ~ c) => (f a -> b) -> f (Endo c) -> b
- fromDualEndoWith :: (FromEndo a, EndoOperatedOn a ~ c) => (a -> b) -> Dual (Endo c) -> b
- fromDualEndoWithF :: (Functor f, FromEndo a, EndoOperatedOn a ~ c) => (f a -> b) -> f (Dual (Endo c)) -> b
- fromEndoTo :: FromEndo a => Endo (EndoOperatedOn a) -> proxy a -> a
- fromDualEndoTo :: FromEndo a => Dual (Endo (EndoOperatedOn a)) -> proxy a -> a
Convert Endo to a Value
Type class provides functionality for converting
and Endo
b
in to some type Dual
(Endo
b)a
. Type b
, on which endomorphism operates,
is implied by type a
, but generally aren't the same type. In other words
it is dual type class to AnEndo
.
type EndoOperatedOn a Source
fromEndo :: Endo (EndoOperatedOn a) -> a Source
Convert endomorphism in to a value of type a
.
fromDualEndo :: Dual (Endo (EndoOperatedOn a)) -> a Source
Provided default implementation:
fromDualEndo
=fromEndo
.
getDual
fromEndoWith :: (FromEndo a, EndoOperatedOn a ~ c) => (a -> b) -> Endo c -> b Source
In a lot of cases it is necessary to evaluate result of fromEndo
.
Example:
>>>
fromEndoWith ((`runState` def) :: State Int () -> ((), Int)) (Endo (+10))
((), 10)
Following property holds:
fromEndoWith
id
=fromEndo
See also fromDualEndoWith
.
fromEndoWithF :: (Functor f, FromEndo a, EndoOperatedOn a ~ c) => (f a -> b) -> f (Endo c) -> b Source
Same as fromEndoWith
, but deals with Endo
wrapped inside a Functor
.
fromDualEndoWith :: (FromEndo a, EndoOperatedOn a ~ c) => (a -> b) -> Dual (Endo c) -> b Source
In a lot of cases it is necessary to evaluate result of fromDualEndo
.
Example:
>>>
fromEndoWith ((`runState` def) :: State Int () -> ((), Int)) (Dual (Endo (+10)))
((), 10)
Following property holds:
fromDualEndoWith
id
=fromDualEndo
See also fromEndoWith
.
fromDualEndoWithF :: (Functor f, FromEndo a, EndoOperatedOn a ~ c) => (f a -> b) -> f (Dual (Endo c)) -> b Source
Same as fromDualEndoWith
, but deals with
wrapped inside
a Dual
Endo
Functor
.
fromEndoTo :: FromEndo a => Endo (EndoOperatedOn a) -> proxy a -> a Source
Variant of fromEndo
that takes type restriction on the result type a
as an argument.
fromDualEndoTo :: FromEndo a => Dual (Endo (EndoOperatedOn a)) -> proxy a -> a Source
Variant of fromDualEndo
that takes type restriction on the result type
a
as an argument.