extensible-0.4.7.2: 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 :: [Assoc k (* -> *)]) a where Source #

A unit of named effects. This is a variant of (:|) specialised for 'Type -> Type'.

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.

castEff :: IncludeAssoc ys xs => Eff xs a -> Eff ys a Source #

Upcast 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 = peelEff1 (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.

peelEff0 Source #

Arguments

:: (a -> Eff xs r)

return the result

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

Handle the foremost type of an action

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

peelEff specialised for continuations with no argument

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

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

peelEff1 Source #

Arguments

:: (a -> b -> Eff xs r)

return the result

-> (forall x. t x -> (x -> b -> Eff xs r) -> b -> Eff xs r)

Handle the foremost type of an action

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

peelEff specialised for 1-argument 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.

peelAction0 Source #

Arguments

:: Function ps (Eff xs q)

Handle the foremost action

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

Non continuation-passing variant of peelAction.

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.

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

Run the frontal state effect and return the final state.

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

Run the frontal state effect and return the final result.

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.

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

Run the frontal state effect.

Maybe

type MaybeEff = Const () Source #

An effect with no result

nothingEff :: Associate k MaybeEff xs => Proxy k -> Eff xs a Source #

Break out of the computation. Similar to Nothing.

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 an action and abort on throwEff.

Iter

data Identity a :: * -> * #

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

Since: 4.8.0.0

Instances

Monad Identity

Since: 4.8.0.0

Methods

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

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

return :: a -> Identity a #

fail :: String -> Identity a #

Functor Identity

Since: 4.8.0.0

Methods

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

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

MonadFix Identity

Since: 4.8.0.0

Methods

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

Applicative Identity

Since: 4.8.0.0

Methods

pure :: a -> Identity a #

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

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

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

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

Foldable Identity

Since: 4.8.0.0

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) #

Arbitrary1 Identity 

Methods

liftArbitrary :: Gen a -> Gen (Identity a) #

liftShrink :: (a -> [a]) -> Identity a -> [Identity a] #

ToJSON1 Identity 

Methods

liftToJSON :: (a -> Value) -> ([a] -> Value) -> Identity a -> Value #

liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Identity a] -> Value #

liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Identity a -> Encoding #

liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Identity a] -> Encoding #

FromJSON1 Identity 

Methods

liftParseJSON :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (Identity a) #

liftParseJSONList :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser [Identity a] #

Eq1 Identity

Since: 4.9.0.0

Methods

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

Ord1 Identity

Since: 4.9.0.0

Methods

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

Read1 Identity

Since: 4.9.0.0

Methods

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

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

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Identity a) #

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Identity a] #

Show1 Identity

Since: 4.9.0.0

Methods

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

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

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 #

NFData1 Identity

Since: 1.4.3.0

Methods

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

Hashable1 Identity 

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Identity a -> Int #

() :=> (Monad Identity) 

Methods

ins :: () :- Monad Identity #

() :=> (Functor Identity) 

Methods

ins :: () :- Functor Identity #

FromBits r a => FromBits r (Identity a) Source # 

Associated Types

type BitWidth (Identity a) :: Nat Source #

Methods

fromBits :: r -> Identity a Source #

toBits :: Identity a -> r Source #

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) 
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

Since: 4.8.0.0

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

Since: 4.8.0.0

Methods

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

show :: Identity a -> String #

showList :: [Identity a] -> ShowS #

Ix a => Ix (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)

Since: 4.9.0.0

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 #

Arbitrary a => Arbitrary (Identity a) 

Methods

arbitrary :: Gen (Identity a) #

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

CoArbitrary a => CoArbitrary (Identity a) 

Methods

coarbitrary :: Identity a -> Gen b -> Gen b #

Hashable a => Hashable (Identity a) 

Methods

hashWithSalt :: Int -> Identity a -> Int #

hash :: Identity a -> Int #

ToJSON a => ToJSON (Identity a) 
ToJSONKey a => ToJSONKey (Identity a) 
FromJSON a => FromJSON (Identity a) 
FromJSONKey a => FromJSONKey (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 -> () #

Generic1 * Identity 

Associated Types

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

Methods

from1 :: f a -> Rep1 Identity f a #

to1 :: Rep1 Identity f a -> f 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) #

(Semigroup a) :=> (Semigroup (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) #

Sieve ((->) LiftedRep LiftedRep) Identity 

Methods

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

Cosieve ((->) LiftedRep LiftedRep) Identity 

Methods

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

data MVector s (Identity a) # 
data MVector s (Identity a) = MV_Identity (MVector s a)
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)))
data Vector (Identity a) # 
type BitWidth (Identity a) Source # 
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 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 the first call of tickEff.

Cont

data ContT k (r :: k) (m :: k -> *) a :: forall k. k -> (k -> *) -> * -> * #

The continuation monad transformer. Can be used to add continuation handling to any type constructor: the Monad instance and most of the operations do not require m to be a monad.

ContT is not a functor on the category of monads, and many operations cannot be lifted through it.

Instances

MonadState s m => MonadState s (ContT * r m) 

Methods

get :: ContT * r m s #

put :: s -> ContT * r m () #

state :: (s -> (a, s)) -> ContT * r m a #

MonadReader r' m => MonadReader r' (ContT * r m) 

Methods

ask :: ContT * r m r' #

local :: (r' -> r') -> ContT * r m a -> ContT * r m a #

reader :: (r' -> a) -> ContT * r m a #

MonadTrans (ContT * r) 

Methods

lift :: Monad m => m a -> ContT * r m a #

Monad (ContT k r m) 

Methods

(>>=) :: ContT k r m a -> (a -> ContT k r m b) -> ContT k r m b #

(>>) :: ContT k r m a -> ContT k r m b -> ContT k r m b #

return :: a -> ContT k r m a #

fail :: String -> ContT k r m a #

Functor (ContT k r m) 

Methods

fmap :: (a -> b) -> ContT k r m a -> ContT k r m b #

(<$) :: a -> ContT k r m b -> ContT k r m a #

MonadFail m => MonadFail (ContT * r m) 

Methods

fail :: String -> ContT * r m a #

Applicative (ContT k r m) 

Methods

pure :: a -> ContT k r m a #

(<*>) :: ContT k r m (a -> b) -> ContT k r m a -> ContT k r m b #

liftA2 :: (a -> b -> c) -> ContT k r m a -> ContT k r m b -> ContT k r m c #

(*>) :: ContT k r m a -> ContT k r m b -> ContT k r m b #

(<*) :: ContT k r m a -> ContT k r m b -> ContT k r m a #

MonadIO m => MonadIO (ContT * r m) 

Methods

liftIO :: IO a -> ContT * r m a #

contEff :: Associate k (ContT r m) xs => Proxy k -> ((a -> m r) -> m r) -> Eff xs a Source #

Place a continuation-passing action.

runContEff :: forall k r xs a. Eff ((k >: ContT r (Eff xs)) ': xs) a -> (a -> Eff xs r) -> Eff xs r Source #

Unwrap a continuation.