predictive-0.1.0: Predict the future, backtrack on failure

Copyright(c) 2016 Ertugrul Söylemez
LicenseBSD3
MaintainerErtugrul Söylemez <esz@posteo.de>
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

Data.Predictive

Contents

Description

 

Synopsis

Predictive scans

data Predictor d s Source #

A predictor tracks information on the current state of type s and deltas of type d. It records a sequence of pending local deltas and the last state known to be consistent on both sides. As remote deltas arrive they are reconciled with the pending local deltas.

Constructors

Predictor

Warning: If you use the constructor directly, keep in mind that for efficiency reasons this library operates under the assumption that the second tuple components of the _predPending field are the predicted states as produced by the corresponding delta.

Fields

predictor Source #

Arguments

:: (d -> d -> Bool)

Do the given deltas agree?

-> (d -> s -> s)

Effect of a delta on the state.

-> s

Initial state.

-> Predictor d s 

Construct a predictor from the given functions and initial state.

predictor_ Source #

Arguments

:: Eq d 
=> (d -> s -> s)

Effect of a deltas on the state.

-> s

Initial state.

-> Predictor d s 

A simplified variant of predictor for cases when deltas agree when they are equal.

Queries

consistent :: Predictor d s -> Bool Source #

Is the given predictor currently consistent? Equivalently: Have all local deltas so far been acknowledged by agreeing remote deltas?

current :: Predictor d s -> s Source #

The current predicted state. If the predictor is consistent, this will agree with lastConsistent.

lastConsistent :: Predictor d s -> s Source #

The last consistent state. If the predictor is consistent, this will agree with current.

pending :: Predictor d s -> Seq (d, s) Source #

Sequence of pending deltas ordered chronologically with the oldest one left together with the effect that delta is predicted to have on the state. If the predictor is consistent, this function returns the empty sequence.

Applying deltas

applyLocal :: d -> Predictor d s -> Predictor d s Source #

Apply the given local delta. This adds it to the sequence of pending deltas.

applyRemote :: d -> Predictor d s -> Predictor d s Source #

Apply the given remote delta.

If the given delta agrees with the oldest pending local delta, this function removes the latter from the pending sequence and marks the new state as the last consistent state. If it disagrees, all pending local deltas are removed and the state is reset to the last consistent state before applying the given delta.