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

Safe HaskellUnsafe

Data.LVar.Generic.Internal

Description

This module contains the unsafe bits that we cannot expose from Data.LVar.Generic.

Synopsis

Documentation

class Foldable (f Trvrsbl) => LVarData1 f whereSource

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 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 aSource

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 whereSource

A class enabling generic creation of new LVars.

Associated Types

type LVContents f a :: ConstraintSource

Requirements for contents types of this LVar.

Methods

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

Instances

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) 

unsafeCoerceLVar :: LVarData1 f => f s1 a -> f s2 bSource

A safer version of unsafeCoerce# (that is, with a slightly more constrained type) for LVars only. Note, that the type of the LVar's contents must be allowed to change, because freezing is recursive.

unsafeTraversable :: LVarData1 f => f Frzn a -> IO (f Trvrsbl a)Source

Here we gain permission to expose the nondeterministic internal structure of an LVar: namely, the order in which its contents occur. We pay the piper with an IO action.