Yampa-0.11: Library for programming hybrid systems.

Copyright(c) Antony Courtney and Henrik Nilsson Yale University 2003
LicenseBSD-style (see the LICENSE file in the distribution)
Portabilitynon-portable (GHC extensions)
Safe HaskellNone



Task abstraction on top of signal transformers.



data Task a b c Source #

A task is a partially SF that may terminate with a result.


Monad (Task a b) Source # 


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

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

return :: a -> Task a b a #

fail :: String -> Task a b a #

Functor (Task a b) Source # 


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

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

Applicative (Task a b) Source # 


pure :: a -> Task a b a #

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

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

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

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

mkTask :: SF a (b, Event c) -> Task a b c Source #

Creates a Task from an SF that returns, as a second output, an Event when the SF terminates. See switch.

runTask :: Task a b c -> SF a (Either b c) Source #

Runs a task.

The output from the resulting signal transformer is tagged with Left while the underlying task is running. Once the task has terminated, the output goes constant with the value Right x, where x is the value of the terminating event.

runTask_ :: Task a b c -> SF a b Source #

Runs a task that never terminates.

The output becomes undefined once the underlying task has terminated.

Convenience function for tasks which are known not to terminate.

taskToSF :: Task a b c -> SF a (b, Event c) Source #

Creates an SF that represents an SF and produces an event when the task terminates, and otherwise produces just an output.

constT :: b -> Task a b c Source #

Non-terminating task with constant output b.

sleepT :: Time -> b -> Task a b () Source #

Sleeps for t seconds with constant output b.

snapT :: Task a b a Source #

Takes a "snapshot" of the input and terminates immediately with the input value as the result.

No time passes; therefore, the following must hold:

snapT >> snapT = snapT

timeOut :: Task a b c -> Time -> Task a b (Maybe c) infixl 0 Source #

Impose a time out on a task.

abortWhen :: Task a b c -> SF a (Event d) -> Task a b (Either c d) infixl 0 Source #

Run a "guarding" event source (SF a (Event b)) in parallel with a (possibly non-terminating) task.

The task will be aborted at the first occurrence of the event source (if it has not terminated itself before that).

Useful for separating sequencing and termination concerns. E.g. we can do something "useful", but in parallel watch for a (exceptional) condition which should terminate that activity, without having to check for that condition explicitly during each and every phase of the activity.

Example: tsk abortWhen lbp

repeatUntil :: Monad m => m a -> (a -> Bool) -> m a infixl 0 Source #

Repeat m until result satisfies the predicate p

for :: Monad m => a -> (a -> a) -> (a -> Bool) -> m b -> m () Source #

C-style for-loop.


>>> for 0 (+1) (>=10) ...

forAll :: Monad m => [a] -> (a -> m b) -> m () Source #

Perform the monadic operation for each element in the list.

forEver :: Monad m => m a -> m b Source #

Repeat m for ever.