CC-delcont- Delimited continuations and dynamically scoped variables

Copyright(c) Dan Doel
MaintainerDan Doel
PortabilityNon-portable (Generalized algebraic data types, Functional Dependencies)
Safe HaskellNone



Implements various cursor datatypes for iterating over collections



data Cursor m r b a where Source

A generalized type that represents a reified data structure traversal. The other traversal data types in this module are special cases of this general type. Cursor is parameterized by four types:

m : The monad in which the Cursor object is usable.

r : The result type, which will be stored in the cursor once the traversal has been completed.

b : The type that the cursor expects to receive before moving on to the next element in the traversal.

a : The element type to which the Cursor provides access at each step in the traversal.


Current :: Monad m => a -> (b -> m (Cursor m r b a)) -> Cursor m r b a 
Done :: Monad m => r -> Cursor m r b a 

type Iterator m a = Cursor m () () a Source

A simple iterator, which provides a way to view each of the elements of a data structure in order.

generator :: MonadDelimitedCont p s m => ((a -> m b) -> m r) -> m (Cursor m r b a) Source

A function for making a cursor out of a free form generator, similar to using yield in Ruby or Python. For example:

generator $ \yield -> do a <- yield 1 ; yield 2 ; b <- yield 3 ; return [a,b]

iterator :: (Foldable t, MonadDelimitedCont p s m) => t a -> m (Iterator m a) Source

Creates an Iterator that will yield each of the elements of a Foldable in order.

current :: Cursor m r b a -> Maybe a Source

Extracts the current element from a cursor, if applicable.

next :: Iterator m a -> m (Iterator m a) Source

Advances an Iterator to the next element (has no effect on a finished Iterator).

open :: (Traversable t, MonadDelimitedCont p s m) => t a -> m (Cursor m (t b) b a) Source

Begins an updating traversal over a Traversable structure. At each step, the cursor will hold an element of type a, and providing an element of type b will move on to the next step. When done, a new Traversable object holding elements of type b will be available.

update :: b -> Cursor m r b a -> m (Cursor m r b a) Source

Provides an item to a Cursor, moving on to the next step in the traversal. (has no effect on a finished Cursor).