Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides the Purify
data type, which wraps a imperative propagator
(for example Data.Propagator.Naive) in a pure data structure.
It provides functions to declare the inputs to these propagators, which are unsafe on their own, but can be instantiated and wrapped to form safe APIs, e.g. Data.Recursive.Bool.
This module is labeled as Internal because its safety depends on the behaviour of the underlying propagator implementation. The assumptions is that
- The defining function passed to
def1
etc. declare a functional relation between the input propagators and the output propagator. - Defining functions do not (observably) affect their input propagators.
- Once all the functions passed to
def1
of a propagator and its dependencies have run,readProp
will return a correct value, i.e. one that satisfies the functional relations. - The order in which the defining functions are executed does not affect the result.
- Termination depends on the termination of the underlying propagator
Synopsis
- data Purify p
- get :: Propagator pa a => Purify pa -> a
- mk :: Propagator p a => a -> Purify p
- def1 :: (Propagator pa a, Propagator pb b) => (pa -> pb -> IO ()) -> Purify pa -> Purify pb
- def2 :: (Propagator pa a, Propagator pb b, Propagator pc c) => (pa -> pb -> pc -> IO ()) -> Purify pa -> Purify pb -> Purify pc
- defList :: (Propagator pa a, Propagator pb b) => ([pa] -> pb -> IO ()) -> [Purify pa] -> Purify pb
Documentation
A value of type Purify p
is a propagator p
, gether with a (lazy)
action to define it.
You can use get
to extract the value from the propagator.
Do not use the extracted value in the definition of that value, this will loop just like a recursive definition with plain values would!
get :: Propagator pa a => Purify pa -> a Source #
Extract the value from a Purify a
. This must not be used when defining that value.
mk :: Propagator p a => a -> Purify p Source #
Any value of type a
is also a value of type Purify p
if p
is a propagator for a
.
def1 :: (Propagator pa a, Propagator pb b) => (pa -> pb -> IO ()) -> Purify pa -> Purify pb Source #
Defines a value of type Purify b
to be a function of the values of Purify a
.
The action passed should declare that relation to the underlying propagator.
The Prop a
propagator must only be used for reading values from.
def2 :: (Propagator pa a, Propagator pb b, Propagator pc c) => (pa -> pb -> pc -> IO ()) -> Purify pa -> Purify pb -> Purify pc Source #
Defines a value of type Purify c
to be a function of the values of Purify a
and Purify b
.
The action passed should declare that relation to the underlying propagator.
The Prop a
and Prop b
propagators must only be used for reading values from.
defList :: (Propagator pa a, Propagator pb b) => ([pa] -> pb -> IO ()) -> [Purify pa] -> Purify pb Source #
Defines a value of type Purify b
to be a function of the values of a list of Purify a
values.
The action passed should declare that relation to the underlying propagator.
The Prop a
propagators must only be used for reading values from.