Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Defines Phases
, an Applicative
transformer for scheduling
effects during different phases of execution.
Synopsis
- data Phases f a where
- runPhasesForwards :: Applicative f => Phases f a -> f a
- runPhasesBackwards :: Applicative f => Phases f a -> f a
- now :: f a -> Phases f a
- later :: Applicative f => f a -> Phases f a
- delay :: Applicative f => Phases f a -> Phases f a
Documentation
data Phases f a where Source #
An applicative transformer to organize effects into an arbitrary number of phases of execution.
Use now
to schedule actions for the current phase of execution:
>>>
say name = putStrLn name *> pure name
>>>
runPhasesForwards $ (,,) <$> now (say "Huey") <*> now (say "Dewey") <*> now (say "Louie")
Huey Dewey Louie ("Huey","Dewey","Louie")
Or later
to schedule it for the next phase of execution:
>>>
runPhasesForwards $ (,,) <$> later (say "Huey") <*> now (say "Dewey") <*> now (say "Louie")
Dewey Louie Huey ("Huey","Dewey","Louie")
And delay
to delay a set of phased actions by one phase:
>>>
runPhasesForwards $ delay ((,,) <$> later (say "Huey") <*> now (say "Dewey")) <*> now (say "Louie")
Louie Dewey Huey ("Huey","Dewey","Louie")
Phases can also be run in reverse, but all actions in the same phase still occur in the same order:
>>>
runPhasesBackwards $ (,,) <$> later (say "Huey") <*> now (say "Dewey") <*> now (say "Louie")
Huey Dewey Louie ("Huey","Dewey","Louie")
Instances
Functor f => Functor (Phases f) Source # | |
Applicative f => Applicative (Phases f) Source # | |
runPhasesForwards :: Applicative f => Phases f a -> f a Source #
run the phased actions in forwards order
>>>
runPhasesForwards $ now (putStrLn "hello") *> later (putStrLn "world")
hello world>>>
runPhasesForwards $ later (putStrLn "hello") *> now (putStrLn "world")
world hello
runPhasesBackwards :: Applicative f => Phases f a -> f a Source #
run the phased actions in backwards order
>>>
runPhasesBackwards $ now (putStrLn "hello") *> later (putStrLn "world")
world hello>>>
runPhasesBackwards $ later (putStrLn "hello") *> now (putStrLn "world")
hello world
later :: Applicative f => f a -> Phases f a Source #
schedule an action to run in the next phase