vinyl-effects-0.0.0: TODO

Safe HaskellNone
LanguageHaskell2010

Vinyl.Effects.Interpreter.Simple

Description

Making interpreters:

Growing interpreters:

Shrinking an interpreter:

If you want to do more with them, just unwrap the newtype and use Data.Vinyl.

Synopsis

Documentation

newtype Interpreter m effects Source

a product of handlers.

each field holds a co-algebra:

f (m a) -> m a

e.g.

runFG :: Interpreter IO '[f,g]
runFG = Interpreter $ HandlerM runF :& HandlerM runG :& RNil

runF :: f (m a) -> m a

runG :: g (m a) -> m a

specialization:

Interpreter IO [f,g]
~
Rec (HandlerM IO) [f,g]
~
(HandlerM IO f, HandlerM IO g)
~
( (forall x. f (IO x) -> IO x)
, (forall y. g (IO y) -> IO y)
)

Constructors

Interpreter 

Fields

getInterpreter :: Rec (HandlerM m) effects
 

newtype HandlerM m f Source

monadically handle a functor.

Constructors

HandlerM 

Fields

getHandlerM :: forall x. f (m x) -> m x
 

data ProductF fs a Source

A (1) lifted, (2) n-ary, (3) associative product.

In particular, a product of "handlers".

fs must all be Functors.

e.g.

ProductF [f,g] a

generalizes '(,)':

ProductF '[f,g] a
~
(f a, g a)

Constructors

ProductF 

Fields

getProductF :: Rec (Apply a) fs
 

interpretLanguage :: Monad m => Interpreter m effects -> Language effects :~> m Source

interpret a language into some monad.

e.g.

interpretLanguage anInterpreter aLanguage :: m ()

calls iterLM.

interpretLanguageF :: Interpreter m effects -> AnAlgebra (LanguageF effects) (m a) Source

you consume a coproduct with a product of consumers i.e. you must handle every case.

like match.

singletonInterpreter :: (forall x. AnAlgebra f (m x)) -> Interpreter m `[f]` Source

make a interpreter from a single handler.

e.g.

data ClipboardF k = GetClipboard (String -> k) | SetClipboard String k deriving Functor

clipboardInterpreter :: Interpreter IO '[ClipboardF] a
clipboardInterpreter = singletonInterpreter $ \case
 GetClipboard f   -> ... >>= f
 SetClipboard s k -> ... s >> k

appendInterpreters :: Interpreter m fs -> Interpreter m gs -> Interpreter m (fs ++ gs) Source

compose two interpreters. ordered.

downcastInterpreter :: gs fs => Interpreter m fs -> Interpreter m gs Source

Discard any number of handlers from the interpreter.

asInterpreter1 :: (Rec (HandlerM m) fs -> Rec (HandlerM m) gs) -> Interpreter m fs -> Interpreter m gs Source

Lift a (unary) function on records to interpreters (a newtype thereof).

e.g.

downcastInterpreter = asInterpreter1 rcast

asInterpreter2 :: (Rec (HandlerM m) fs -> Rec (HandlerM m) gs -> Rec (HandlerM m) hs) -> Interpreter m fs -> Interpreter m gs -> Interpreter m hs Source

Lift an operation on records to interpreters (a newtype thereof).

e.g.

appendInterpreters = asInterpreter2 (<+>)

fromSingletonInterpreter :: Interpreter m `[f]` -> AnAlgebra f (m a) Source

inverts singletonInterpreter, for convenient access.