vinyl-effects-0.0.0: TODO

Safe HaskellNone
LanguageHaskell2010

Vinyl.Effects.Language

Description

 

Synopsis

Documentation

newtype Language effects a Source

a domain-specific language that supports the effects.

e.g.

Language [f,g] a

Constructors

Language 

Fields

getLanguage :: FreeF (LanguageF effects) a (Language effects a)
 

Instances

Monad (Language effects) Source

>>= may call Free

Functor (Language effects) Source

fmap

Applicative (Language effects) Source

pure calls Pure

MonadLanguage (Language effects) effects Source

The simplest concrete implementation for the interface.

Analogous to (m ~ State s) for (MonadState m s).

liftL = liftE >>> liftF
MonadFree (LanguageF effects) (Language effects) Source 

newtype LanguageF effects a Source

a (type-level) sum of "language features". Generally, a (1) lifted, (2) n-ary, (3) associative sum.

the expression may use any effect in effects:

expression :: LanguageF effects

generalizes Either:

LanguageF '[f,g] a
~
Either (f a) (g a)

Constructors

LanguageF 

Fields

getLanguageF :: CoRec (Apply a) effects
 

Instances

Functor (LanguageF effects) Source 
MonadFree (LanguageF effects) (Language effects) Source 

liftE :: (effect effects, Functor effect) => effect a -> LanguageF effects a Source

"inject" an effect into a set of effects.

generalizes Left and Right:

  • Left  ~ (liftE :: f a -> LanguageF '[f,g] a)
  • Right ~ (liftE :: g a -> LanguageF '[f,g] a)

class Monad m => MonadLanguage m effects | m -> effects where Source

the monad supports each effect

a "final encoding" (TODO, is it?) for injecting functors into a sum.

Analogous to liftF.

e.g.

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

getClipboard :: (MonadClipboard m effects) => m String
getClipboard = liftL $ GetClipboard id
   -- GetClipboard id :: ClipboardF String

setClipboard :: (MonadClipboard m effects) => String -> m ())
setClipboard s = liftL $ SetClipboard s ()
  -- SetClipboard s () :: ClipboardF ()

type MonadClipboard m effects = (MonadLanguage m effects, ClipboardF ∈ effects)

the FunctionalDependency (i.e. m -> effects) says: "a language-monad supports one set of effects".

Methods

liftL :: (f effects, Functor f) => f a -> m a Source

Instances

MonadLanguage (Language effects) effects Source

The simplest concrete implementation for the interface.

Analogous to (m ~ State s) for (MonadState m s).

liftL = liftE >>> liftF
Monoid w => MonadLanguage (RWS r w s) ((:) (* -> *) (ReaderF r) ((:) (* -> *) (WriterF w) ((:) (* -> *) (StateF s) ([] (* -> *))))) Source 

fromUnitLanguageF :: forall f a. LanguageF `[f]` a -> f a Source

fromLanguage :: Language effects a -> Free (LanguageF effects) a Source

cast a (newtype'd) Language to Free. TODO is cheap (can use coerce)?

iterL :: (LanguageF effects a -> a) -> Language effects a -> a Source

wraps iter.

iterLM :: Monad m => (LanguageF effects (m a) -> m a) -> Language effects a -> m a Source

wraps iterM.