extensible-0.4.1: Extensible, efficient, optics-friendly data types and effects

Copyright(c) Fumiaki Kinoshita 2017
LicenseBSD3
MaintainerFumiaki Kinoshita <fumiexcel@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Data.Extensible.Effect

Contents

Description

Name-based extensible effects

Synopsis

Base

data Instruction xs a where Source #

A unit of named effects.

Constructors

Instruction :: !(Membership xs kv) -> AssocValue kv a -> Instruction xs a 

type Eff xs = Skeleton (Instruction xs) Source #

The extensible operational monad

liftEff :: forall s t xs a. Associate s t xs => Proxy s -> t a -> Eff xs a Source #

Lift an instruction onto an Eff action.

liftsEff :: forall s t xs a r. Associate s t xs => Proxy s -> t a -> (a -> r) -> Eff xs r Source #

Lift an instruction onto an Eff action and apply a function to the result.

hoistEff :: forall s t xs a. Associate s t xs => Proxy s -> (forall x. t x -> t x) -> Eff xs a -> Eff xs a Source #

Censor a specific type of effects in an action.

Step-wise handling

newtype Interpreter f g Source #

Transformation between effects

Constructors

Interpreter 

Fields

handleEff :: RecordOf (Interpreter m) xs -> Eff xs a -> MonadView m (Eff xs) a Source #

Process an Eff action using a record of Interpreters.

Peeling

peelEff Source #

Arguments

:: Rebinder xs r

Re-bind an unrelated action

-> (a -> r)

return the result

-> (forall x. t x -> (x -> r) -> r)

Handle the foremost type of an action

-> Eff ((k >: t) ': xs) a 
-> r 

Build a relay-style handler from a triple of functions.

runStateEff = peelEff rebindEff1 (a s -> return (a, s))
  (m k s -> let (a, s') = runState m s in k a s')

type Rebinder xs r = forall x. Instruction xs x -> (x -> r) -> r Source #

A function to bind an Instruction in peelEff.

rebindEff0 :: Rebinder xs (Eff xs r) Source #

A common value for the second argument of peelEff. Binds an instruction directly.

rebindEff1 :: Rebinder xs (a -> Eff xs r) Source #

A pre-defined value for the second argument of peelEff. Preserves the argument of the continuation.

rebindEff2 :: Rebinder xs (a -> b -> Eff xs r) Source #

A pre-defined value for the second argument of peelEff. Preserves two arguments of the continuation.

leaveEff :: Eff '[] a -> a Source #

Reveal the final result of Eff.

retractEff :: forall k m a. Monad m => Eff '[k >: m] a -> m a Source #

Tear down an action using the Monad instance of the instruction.

Anonymous actions

data Action args a r where Source #

Anonymous representation of instructions.

Constructors

AResult :: Action '[] a a 
AArgument :: x -> Action xs a r -> Action (x ': xs) a r 

type family Function args r :: * where ... Source #

Function [a, b, c] r is a -> b -> c -> r

Equations

Function '[] r = r 
Function (x ': xs) r = x -> Function xs r 

runAction :: Function xs (f a) -> Action xs a r -> f r Source #

Pass the arguments of Action to the supplied function.

(@!?) :: FieldName k -> Function xs (f a) -> Field (Interpreter f) (k :> Action xs a) infix 1 Source #

Create a Field of a Interpreter for an Action.

peelAction Source #

Arguments

:: (forall x. Instruction xs x -> (x -> r) -> r)

Re-bind an unrelated action

-> (a -> r)

return the result

-> Function ps ((q -> r) -> r)

Handle the foremost action

-> Eff ((k >: Action ps q) ': xs) a 
-> r 

Specialised version of peelEff for Actions. You can pass a function a -> b -> ... -> (q -> r) -> r as a handler for Action '[a, b, ...] q.

transformers-compatible actions and handlers

Reader

type ReaderEff = (:~:) Source #

The reader monad is characterised by a type equality between the result type and the enviroment type.

askEff :: forall k r xs. Associate k (ReaderEff r) xs => Proxy k -> Eff xs r Source #

Fetch the environment.

asksEff :: forall k r xs a. Associate k (ReaderEff r) xs => Proxy k -> (r -> a) -> Eff xs a Source #

Pass the environment to a function.

localEff :: forall k r xs a. Associate k (ReaderEff r) xs => Proxy k -> (r -> r) -> Eff xs a -> Eff xs a Source #

Modify the enviroment locally.

runReaderEff :: forall k r xs a. Eff ((k >: ReaderEff r) ': xs) a -> r -> Eff xs a Source #

Run the frontal reader effect.

State

type State s = StateT s Identity #

A state monad parameterized by the type s of the state to carry.

The return function leaves the state unchanged, while >>= uses the final state of the first computation as the initial state of the second.

getEff :: forall k s xs. Associate k (State s) xs => Proxy k -> Eff xs s Source #

Get the current state.

getsEff :: forall k s a xs. Associate k (State s) xs => Proxy k -> (s -> a) -> Eff xs a Source #

Pass the current state to a function.

putEff :: forall k s xs. Associate k (State s) xs => Proxy k -> s -> Eff xs () Source #

Replace the state with a new value.

modifyEff :: forall k s xs. Associate k (State s) xs => Proxy k -> (s -> s) -> Eff xs () Source #

Modify the state.

stateEff :: forall k s xs a. Associate k (State s) xs => Proxy k -> (s -> (a, s)) -> Eff xs a Source #

Lift a state modification function.

runStateEff :: forall k s xs a. Eff ((k >: State s) ': xs) a -> s -> Eff xs (a, s) Source #

Run the frontal state effect.

Writer

type WriterEff w = (,) w Source #

(,) already is a writer monad.

writerEff :: forall k w xs a. Associate k (WriterEff w) xs => Proxy k -> (a, w) -> Eff xs a Source #

Write the second element and return the first element.

tellEff :: forall k w xs. Associate k (WriterEff w) xs => Proxy k -> w -> Eff xs () Source #

Write a value.

listenEff :: forall k w xs a. (Associate k (WriterEff w) xs, Monoid w) => Proxy k -> Eff xs a -> Eff xs (a, w) Source #

Squash the outputs into one step and return it.

passEff :: forall k w xs a. (Associate k (WriterEff w) xs, Monoid w) => Proxy k -> Eff xs (a, w -> w) -> Eff xs a Source #

Modify the output using the function in the result.

runWriterEff :: forall k w xs a. Monoid w => Eff ((k >: WriterEff w) ': xs) a -> Eff xs (a, w) Source #

Run the frontal writer effect.

Maybe

type MaybeEff = Const () Source #

An effect with no result

runMaybeEff :: forall k xs a. Eff ((k >: MaybeEff) ': xs) a -> Eff xs (Maybe a) Source #

Run an effect which may fail in the name of k.

Either

type EitherEff = Const Source #

Throwing an exception

throwEff :: Associate k (EitherEff e) xs => Proxy k -> e -> Eff xs a Source #

Throw an exception e, throwing the rest of the computation away.

catchEff :: forall k e xs a. Associate k (EitherEff e) xs => Proxy k -> Eff xs a -> (e -> Eff xs a) -> Eff xs a Source #

Attach a handler for an exception.

runEitherEff :: forall k e xs a. Eff ((k >: EitherEff e) ': xs) a -> Eff xs (Either e a) Source #

Run the frontal Either effect.

Iter

data Identity a :: * -> * #

Identity functor and monad. (a non-strict monad)

Since: 4.8.0.0

Instances

Monad Identity 

Methods

(>>=) :: Identity a -> (a -> Identity b) -> Identity b #

(>>) :: Identity a -> Identity b -> Identity b #

return :: a -> Identity a #

fail :: String -> Identity a #

Functor Identity 

Methods

fmap :: (a -> b) -> Identity a -> Identity b #

(<$) :: a -> Identity b -> Identity a #

MonadFix Identity 

Methods

mfix :: (a -> Identity a) -> Identity a #

Applicative Identity 

Methods

pure :: a -> Identity a #

(<*>) :: Identity (a -> b) -> Identity a -> Identity b #

(*>) :: Identity a -> Identity b -> Identity b #

(<*) :: Identity a -> Identity b -> Identity a #

Foldable Identity 

Methods

fold :: Monoid m => Identity m -> m #

foldMap :: Monoid m => (a -> m) -> Identity a -> m #

foldr :: (a -> b -> b) -> b -> Identity a -> b #

foldr' :: (a -> b -> b) -> b -> Identity a -> b #

foldl :: (b -> a -> b) -> b -> Identity a -> b #

foldl' :: (b -> a -> b) -> b -> Identity a -> b #

foldr1 :: (a -> a -> a) -> Identity a -> a #

foldl1 :: (a -> a -> a) -> Identity a -> a #

toList :: Identity a -> [a] #

null :: Identity a -> Bool #

length :: Identity a -> Int #

elem :: Eq a => a -> Identity a -> Bool #

maximum :: Ord a => Identity a -> a #

minimum :: Ord a => Identity a -> a #

sum :: Num a => Identity a -> a #

product :: Num a => Identity a -> a #

Traversable Identity 

Methods

traverse :: Applicative f => (a -> f b) -> Identity a -> f (Identity b) #

sequenceA :: Applicative f => Identity (f a) -> f (Identity a) #

mapM :: Monad m => (a -> m b) -> Identity a -> m (Identity b) #

sequence :: Monad m => Identity (m a) -> m (Identity a) #

Generic1 Identity 

Associated Types

type Rep1 (Identity :: * -> *) :: * -> * #

Methods

from1 :: Identity a -> Rep1 Identity a #

to1 :: Rep1 Identity a -> Identity a #

Eq1 Identity 

Methods

liftEq :: (a -> b -> Bool) -> Identity a -> Identity b -> Bool #

Ord1 Identity 

Methods

liftCompare :: (a -> b -> Ordering) -> Identity a -> Identity b -> Ordering #

Read1 Identity 

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Identity a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Identity a] #

Show1 Identity 

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Identity a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Identity a] -> ShowS #

MonadZip Identity 

Methods

mzip :: Identity a -> Identity b -> Identity (a, b) #

mzipWith :: (a -> b -> c) -> Identity a -> Identity b -> Identity c #

munzip :: Identity (a, b) -> (Identity a, Identity b) #

Comonad Identity 

Methods

extract :: Identity a -> a #

duplicate :: Identity a -> Identity (Identity a) #

extend :: (Identity a -> b) -> Identity a -> Identity b #

ComonadApply Identity 

Methods

(<@>) :: Identity (a -> b) -> Identity a -> Identity b #

(@>) :: Identity a -> Identity b -> Identity b #

(<@) :: Identity a -> Identity b -> Identity a #

Sieve (->) Identity 

Methods

sieve :: (a -> b) -> a -> Identity b #

Cosieve (->) Identity 

Methods

cosieve :: (a -> b) -> Identity a -> b #

() :=> (Monad Identity) 

Methods

ins :: () :- Monad Identity #

() :=> (Functor Identity) 

Methods

ins :: () :- Functor Identity #

Bounded a => Bounded (Identity a) 
Enum a => Enum (Identity a) 
Eq a => Eq (Identity a) 

Methods

(==) :: Identity a -> Identity a -> Bool #

(/=) :: Identity a -> Identity a -> Bool #

Floating a => Floating (Identity a) 
Fractional a => Fractional (Identity a) 
Integral a => Integral (Identity a) 
Data a => Data (Identity a) 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Identity a -> c (Identity a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Identity a) #

toConstr :: Identity a -> Constr #

dataTypeOf :: Identity a -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Identity a)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Identity a)) #

gmapT :: (forall b. Data b => b -> b) -> Identity a -> Identity a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Identity a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Identity a -> r #

gmapQ :: (forall d. Data d => d -> u) -> Identity a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Identity a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Identity a -> m (Identity a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Identity a -> m (Identity a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Identity a -> m (Identity a) #

Num a => Num (Identity a) 
Ord a => Ord (Identity a) 

Methods

compare :: Identity a -> Identity a -> Ordering #

(<) :: Identity a -> Identity a -> Bool #

(<=) :: Identity a -> Identity a -> Bool #

(>) :: Identity a -> Identity a -> Bool #

(>=) :: Identity a -> Identity a -> Bool #

max :: Identity a -> Identity a -> Identity a #

min :: Identity a -> Identity a -> Identity a #

Read a => Read (Identity a)

This instance would be equivalent to the derived instances of the Identity newtype if the runIdentity field were removed

Real a => Real (Identity a) 

Methods

toRational :: Identity a -> Rational #

RealFloat a => RealFloat (Identity a) 
RealFrac a => RealFrac (Identity a) 

Methods

properFraction :: Integral b => Identity a -> (b, Identity a) #

truncate :: Integral b => Identity a -> b #

round :: Integral b => Identity a -> b #

ceiling :: Integral b => Identity a -> b #

floor :: Integral b => Identity a -> b #

Show a => Show (Identity a)

This instance would be equivalent to the derived instances of the Identity newtype if the runIdentity field were removed

Methods

showsPrec :: Int -> Identity a -> ShowS #

show :: Identity a -> String #

showList :: [Identity a] -> ShowS #

Ix a => Ix (Identity a) 
IsString a => IsString (Identity a) 

Methods

fromString :: String -> Identity a #

Generic (Identity a) 

Associated Types

type Rep (Identity a) :: * -> * #

Methods

from :: Identity a -> Rep (Identity a) x #

to :: Rep (Identity a) x -> Identity a #

Semigroup a => Semigroup (Identity a) 

Methods

(<>) :: Identity a -> Identity a -> Identity a #

sconcat :: NonEmpty (Identity a) -> Identity a #

stimes :: Integral b => b -> Identity a -> Identity a #

Monoid a => Monoid (Identity a) 

Methods

mempty :: Identity a #

mappend :: Identity a -> Identity a -> Identity a #

mconcat :: [Identity a] -> Identity a #

Storable a => Storable (Identity a) 

Methods

sizeOf :: Identity a -> Int #

alignment :: Identity a -> Int #

peekElemOff :: Ptr (Identity a) -> Int -> IO (Identity a) #

pokeElemOff :: Ptr (Identity a) -> Int -> Identity a -> IO () #

peekByteOff :: Ptr b -> Int -> IO (Identity a) #

pokeByteOff :: Ptr b -> Int -> Identity a -> IO () #

peek :: Ptr (Identity a) -> IO (Identity a) #

poke :: Ptr (Identity a) -> Identity a -> IO () #

Bits a => Bits (Identity a) 
FiniteBits a => FiniteBits (Identity a) 
NFData a => NFData (Identity a)

Since: 1.4.0.0

Methods

rnf :: Identity a -> () #

Wrapper * Identity Source # 

Associated Types

type Repr Identity (h :: Identity -> *) (v :: Identity) :: * Source #

Methods

_Wrapper :: (Functor f, Profunctor p) => Optic' * * p f (h v) (Repr Identity h v) Source #

(Bounded a) :=> (Bounded (Identity a)) 

Methods

ins :: Bounded a :- Bounded (Identity a) #

(Enum a) :=> (Enum (Identity a)) 

Methods

ins :: Enum a :- Enum (Identity a) #

(Eq a) :=> (Eq (Identity a)) 

Methods

ins :: Eq a :- Eq (Identity a) #

(Floating a) :=> (Floating (Identity a)) 

Methods

ins :: Floating a :- Floating (Identity a) #

(Fractional a) :=> (Fractional (Identity a)) 
(Integral a) :=> (Integral (Identity a)) 

Methods

ins :: Integral a :- Integral (Identity a) #

(Num a) :=> (Num (Identity a)) 

Methods

ins :: Num a :- Num (Identity a) #

(Ord a) :=> (Ord (Identity a)) 

Methods

ins :: Ord a :- Ord (Identity a) #

(Read a) :=> (Read (Identity a)) 

Methods

ins :: Read a :- Read (Identity a) #

(Real a) :=> (Real (Identity a)) 

Methods

ins :: Real a :- Real (Identity a) #

(RealFloat a) :=> (RealFloat (Identity a)) 
(RealFrac a) :=> (RealFrac (Identity a)) 

Methods

ins :: RealFrac a :- RealFrac (Identity a) #

(Show a) :=> (Show (Identity a)) 

Methods

ins :: Show a :- Show (Identity a) #

(Monoid a) :=> (Monoid (Identity a)) 

Methods

ins :: Monoid a :- Monoid (Identity a) #

(Bits a) :=> (Bits (Identity a)) 

Methods

ins :: Bits a :- Bits (Identity a) #

type Rep1 Identity 
type Rep1 Identity = D1 (MetaData "Identity" "Data.Functor.Identity" "base" True) (C1 (MetaCons "Identity" PrefixI True) (S1 (MetaSel (Just Symbol "runIdentity") NoSourceUnpackedness NoSourceStrictness DecidedLazy) Par1))
type Rep (Identity a) 
type Rep (Identity a) = D1 (MetaData "Identity" "Data.Functor.Identity" "base" True) (C1 (MetaCons "Identity" PrefixI True) (S1 (MetaSel (Just Symbol "runIdentity") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)))
type Repr * Identity a Source # 
type Repr * Identity a = a

tickEff :: Associate k Identity xs => Proxy k -> Eff xs () Source #

Put a milestone on a computation.

runIterEff :: Eff ((k >: Identity) ': xs) a -> Eff xs (Either a (Eff ((k >: Identity) ': xs) a)) Source #

Run a computation until tickEff.