data-kiln-0.1.0.0: Sculpt mutable recursive data with reference equality; bake it using a data kiln into an immutable lazy structure

Safe HaskellNone
LanguageHaskell2010

Data.Kiln

Synopsis

Documentation

data Clay s f Source

A Clay s f is a recursive structure with a uniquely-identified mutable reference at each node. It cannot escape the Squishy monad, by means of the same mechanism as used in Control.Monad.ST.

newClay :: f (Clay s f) -> Squishy s (Clay s f) Source

Take a container f (Clay s f), and wrap it in a new mutable reference and distinct tag, returning a new Clay s f.

readClay :: Clay s f -> Squishy s (f (Clay s f)) Source

Takes a Clay s f and exposes the first level of f (Clay s f) inside it.

modifyClay :: Clay s f -> (f (Clay s f) -> f (Clay s f)) -> Squishy s () Source

Use the provided function to destructively update the value at this node of a Clay s f.

writeClay :: Clay s f -> f (Clay s f) -> Squishy s () Source

Set a piece of Clay to a particular value.

identifyClay :: Clay s f -> Identifier s Source

Get the unique Identifier for a piece of Clay.

kiln :: Traversable f => Clay s f -> Squishy s (Fix f) Source

Freeze a Clay using the identity transformation, so that a Clay s f turns into a Fix f.

kilnWith :: forall s f g. Traversable f => (forall a. f a -> g a) -> Clay s f -> Squishy s (Fix g) Source

Given a Clay s f, use a natural transformation (forall a. f a -> g a) to convert it into the fixed-point of a the functor g by eliminating the indirection of the mutable references and using the distinct tags on the structure's parts to tie knots where there are cycles in the original graph of references. TThe result is an immutable cyclic lazy data structure.

runKilningWith :: Traversable f => (forall a. f a -> g a) -> (forall s. Squishy s (Clay s f)) -> Fix g Source

Given a Squishy monad action which returns a Clay s f, run the action and use the provided natural transformation during baking (see kilnWith).

runKilning :: Traversable f => (forall s. Squishy s (Clay s f)) -> Fix f Source

Given a Squishy monad action which returns a Clay s f, run the action and kiln the result.