Copyright | (c) Antony Courtney and Henrik Nilsson Yale University 2003 |
---|---|

License | BSD-style (see the LICENSE file in the distribution) |

Maintainer | nilsson@cs.yale.edu |

Stability | provisional |

Portability | non-portable (GHC extensions) |

Safe Haskell | None |

Language | Haskell98 |

Task abstraction on top of signal transformers.

## Synopsis

- data Task a b c
- mkTask :: SF a (b, Event c) -> Task a b c
- runTask :: Task a b c -> SF a (Either b c)
- runTask_ :: Task a b c -> SF a b
- taskToSF :: Task a b c -> SF a (b, Event c)
- constT :: b -> Task a b c
- sleepT :: Time -> b -> Task a b ()
- snapT :: Task a b a
- timeOut :: Task a b c -> Time -> Task a b (Maybe c)
- abortWhen :: Task a b c -> SF a (Event d) -> Task a b (Either c d)
- repeatUntil :: Monad m => m a -> (a -> Bool) -> m a
- for :: Monad m => a -> (a -> a) -> (a -> Bool) -> m b -> m ()
- forAll :: Monad m => [a] -> (a -> m b) -> m ()
- forEver :: Monad m => m a -> m b

# Documentation

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

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.

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

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.

Example:

`>>>`

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