lvish-2.0: Parallel scheduler, LVar data structures, and infrastructure to build more.

Safe HaskellTrustworthy

Data.LVar.Generic

Contents

Description

A generic interface providing operations that work on all LVars.

Synopsis

Classes containing the generic interfaces

class Foldable (f Trvrsbl) => LVarData1 f where

A class representing monotonic data structures that take one type parameter, as well as an s parameter for session safety.

LVars that fall into this class are typically collection types.

Methods

addHandler :: Maybe HandlerPool -> f s elt -> (elt -> Par e s ()) -> Par e s ()

Add a handler function which is called whenever an element is added to the LVar.

freeze :: HasFreeze e => f s a -> Par e s (f Frzn a)

An O(1) operation that atomically switches the LVar into a frozen state. Any threads waiting on the freeze are woken.

The contents of a frozen LVar are fully observable: e.g., a whole set instead of one element, or the full/empty information for an IVar, instead of just the payload.

However, note that Frzn LVars cannot be folded, because they may have nondeterministic ordering after being frozen. See sortFreeze.

sortFrzn :: Ord a => f Frzn a -> AFoldable a

Perform a freeze followed by a sort operation which guarantees that the elements produced will be produced in a deterministic order. The result is fully accessible to the user (Foldable).

Instances

LVarData1 IVar

An IVar can be treated as a generic container LVar which happens to contain at most one value! Note, however, that the polymorphic operations are less useful than the monomorphic ones exposed by this module.

LVarData1 IStructure

An IStructure can be treated as a generic container LVar. However, the polymorphic operations are less useful than the monomorphic ones exposed by this module (e.g., forEachHP vs. addHandler).

LVarData1 ISet

An ISet can be treated as a generic container LVar. However, the polymorphic operations are less useful than the monomorphic ones exposed by this module.

LVarData1 ISet

An ISet can be treated as a generic container LVar.

LVarData1 (IMap k)

An IMap can be treated as a generic container LVar. However, the polymorphic operations are less useful than the monomorphic ones exposed by this module.

LVarData1 (IMap k)

An IMap can be treated as a generic container LVar. However, the polymorphic operations are less useful than the monomorphic ones exposed by this module.

class LVarWBottom f where

A class enabling generic creation of new LVars.

Associated Types

type LVContents f a :: Constraint

Requirements for contents types of this LVar.

Methods

newBottom :: LVContents f a => Par e s (f s a)

class LVarData1 f => OrderedLVarData1 f where

Some LVar datatypes are stored in an internally ordered way so that it is then possible to take O(1) frozen snapshots and consume them inexpensively in a deterministic order.

LVars with this additional property provide this class as well as LVarData1.

Methods

snapFreeze :: HasFreeze e => f s a -> Par e s (f Trvrsbl a)

Don't just freeze the LVar, but make the full contents completely available and Foldable. Guaranteed O(1).

Instances

OrderedLVarData1 IStructure

The IStructures in this module also have the special property that they support a freeze operation which immediately yields a Foldable container without any sorting (see snapFreeze).

OrderedLVarData1 ISet

The ISets in this module also have the special property that they support an O(1) freeze operation which immediately yields a Foldable container (snapFreeze).

OrderedLVarData1 ISet

The ISets in this module also have the special property that they support an O(1) freeze operation which immediately yields a Foldable container (snapFreeze).

OrderedLVarData1 (IMap k)

The IMaps in this module also have the special property that they support an O(1) freeze operation which immediately yields a Foldable container (snapFreeze).

OrderedLVarData1 (IMap k)

The IMaps in this module also have the special property that they support an O(1) freeze operation which immediately yields a Foldable container (snapFreeze).

Supporting types and utilities

data AFoldable a

Carries a Foldable type, but you don't get to know which one. The purpose of this type is that sortFreeze should not have to impose a particular memory representation.

Constructors

forall f2 . Foldable f2 => AFoldable (f2 a) 

Instances

Show a => Show (AFoldable a) 

castFrzn :: LVarData1 f => f Trvrsbl a -> f Frzn a

Trvrsbl is a stronger property than Frzn, so it is always safe to "upcast" to the weaker version.

forFrzn :: LVarData1 f => f Frzn a -> (a -> Par e s ()) -> Par e s ()

LVish Par actions must commute, therefore one safe way to consume a frozen (but unordered) LVar, even in another runPar session, is to run a Par computation for each element.