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

Safe HaskellTrustworthy
LanguageHaskell98

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 Source

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.

The superclass constraint on this class serves to ensure that once frozen, the LVar contents are foldable.

Minimal complete definition

addHandler, freeze

Methods

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

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

freeze :: f s a -> Par QuasiDet s (f Frzn a) Source

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 Source

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 (SatMap k)

An SatMap 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 Source

A class enabling generic creation of new LVars.

Associated Types

type LVContents f a :: Constraint Source

Requirements for contents types of this LVar.

Methods

newBottom :: LVContents f a => Par d s (f s a) Source

Instances

class LVarData1 f => OrderedLVarData1 f where Source

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 :: f s a -> Par QuasiDet s (f Trvrsbl a) Source

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 (SatMap k)

The SatMaps 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 Source

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 Source

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 d s ()) -> Par d s () Source

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.