endo-0.3.0.0: Endomorphism utilities.

Copyright(c) 2015, Peter Trško
LicenseBSD3
Maintainerpeter.trsko@gmail.com
Stabilityexperimental
PortabilityNoImplicitPrelude
Safe HaskellSafe
LanguageHaskell2010

Data.Monoid.Endo.FromEndo

Contents

Description

Convert endomorphism in to a value.

Synopsis

Convert Endo to a Value

class FromEndo a where Source

Type class provides functionality for converting Endo b and Dual (Endo b) in to some type 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.

Minimal complete definition

fromEndo

Associated Types

type EndoOperatedOn a Source

Methods

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

Instances

FromEndo e => FromEndo (Dual e) Source 
FromEndo (Endo a) Source 
FromEndo (a -> a) Source 
Monad f => FromEndo (ReaderT r f r) Source

Retrieve environment modified by endomorphism.

fromEndo (Endo f) = asks f
Monad f => FromEndo (StateT s f ()) Source

Modify state.

fromEndo (Endo f) = modify f
Monad f => FromEndo (StateT s f ()) Source

Modify state.

fromEndo (Endo f) = modify f
MonadState s m => FromEndo (ApplyEndo Modify' m s) Source

Evaluates ApplyEndo in terms of state operation:

fromEndo (Endo f) = ApplyEndo . state $ \s ->
    let s' = f s in s' `seq` (s', s')
MonadState s m => FromEndo (ApplyEndo Modify m s) Source

Evaluates ApplyEndo in terms of state operation:

fromEndo e = ApplyEndo . state $ \s ->
    let s' = appEndo e s in (s', s')
MonadReader r m => FromEndo (ApplyEndo Reader m r) Source

Evaluates ApplyEndo in terms of asks operation:

fromEndo = ApplyEndo . asks . appEndo
(Applicative f, Default a) => FromEndo (ApplyEndo Def f a) Source 
(Applicative f, Monoid a) => FromEndo (ApplyEndo Mempty f a) Source 
(Monoid w, Monad f) => FromEndo (RWST r w s f ()) Source

Modify state.

fromEndo (Endo f) = modify f
(Monoid w, Monad f) => FromEndo (RWST r w s f ()) Source

Modify state.

fromEndo (Endo f) = modify f

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 Dual Endo wrapped inside a 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.