small-steps-0.1.0.0: Small step semantics
Safe Haskell None
Language Haskell2010

Control.State.Transition.Extended

Description

Small step state transition systems.

Synopsis

Documentation

class RuleTypeRep t Source #

Minimal complete definition

rTypeRep

Instances

Instances details
RuleTypeRep ' Initial Source #
Instance details

Defined in Control.State.Transition.Extended

Methods

rTypeRep :: SRuleType ' Initial

RuleTypeRep ' Transition Source #
Instance details

Defined in Control.State.Transition.Extended

Methods

rTypeRep :: SRuleType ' Transition

newtype IRC sts Source #

Context available to initial rules.

Constructors

IRC ( Environment sts)

newtype TRC sts Source #

Context available to transition rules.

Constructors

TRC ( Environment sts, State sts, Signal sts)

type Rule sts rtype = F (Clause sts rtype) Source #

data Assertion sts Source #

An assertion is a validation condition for the STS system in question. It should be used to define properties of the system as a whole that cannot be violated under normal circumstances - e.g. a violation implies a failing in the rule logic.

Assertions should not check for conditions that may differ between different rules in a system, since the interpreter may stop the system upon presence of a failed assertion.

Whether assertions are checked is a matter for the STS interpreter.

Constructors

PreCondition String ( TRC sts -> Bool )

Pre-condition. Checked before the rule fires.

PostCondition String ( TRC sts -> State sts -> Bool )

Post-condition. Checked after the rule fires, and given access to the resultant state as well as the initial context.

class ( Eq ( PredicateFailure a), Show ( PredicateFailure a), Monad ( BaseM a), Typeable a) => STS a where Source #

State transition system.

Minimal complete definition

transitionRules

Associated Types

type State a :: Type Source #

Type of the state which the system transitions between.

type Signal a :: Type Source #

Signal triggering a state change.

type Environment a :: Type Source #

Environment type.

type BaseM a :: Type -> Type Source #

Monad into which to interpret the rules.

type Event a :: Type Source #

Event type.

type PredicateFailure a :: Type Source #

Descriptive type for the possible failures which might cause a transition to fail.

As a convention, PredicateFailure s which are "structural" (meaning that they are not "throwable" in practice, and are used to pass control from one transition rule to another) are prefixed with S_ .

Structural PredicateFailure s represent conditions between rules where the disjunction of all rules' preconditions is equal to True . That is, either one rule will throw a structural PredicateFailure and the other will succeed, or vice-versa.

Methods

initialRules :: [ InitialRule a] Source #

Rules governing transition under this system.

transitionRules :: [ TransitionRule a] Source #

assertions :: [ Assertion a] Source #

Assertions about the transition system.

renderAssertionViolation :: AssertionViolation a -> String Source #

Render an assertion violation.

Defaults to using show , but note that this does not know how to render the context. So for more information you should define your own renderer here.

data STUB (e :: Type ) (st :: Type ) (si :: Type ) (f :: Type ) (m :: Type -> Type ) Source #

A stub rule with no transitions to use as a placeholder

Instances

Instances details
( Eq f, Monad m, Show f, Typeable e, Typeable f, Typeable si, Typeable st, Typeable m) => STS ( STUB e st si f m) Source #
Instance details

Defined in Control.State.Transition.Extended

Associated Types

type State ( STUB e st si f m) Source #

type Signal ( STUB e st si f m) Source #

type Environment ( STUB e st si f m) Source #

type BaseM ( STUB e st si f m) :: Type -> Type Source #

type Event ( STUB e st si f m) Source #

type PredicateFailure ( STUB e st si f m) Source #

type State ( STUB e st si f m) Source #
Instance details

Defined in Control.State.Transition.Extended

type State ( STUB e st si f m) = st
type Signal ( STUB e st si f m) Source #
Instance details

Defined in Control.State.Transition.Extended

type Signal ( STUB e st si f m) = si
type Environment ( STUB e st si f m) Source #
Instance details

Defined in Control.State.Transition.Extended

type Environment ( STUB e st si f m) = e
type BaseM ( STUB e st si f m) Source #
Instance details

Defined in Control.State.Transition.Extended

type BaseM ( STUB e st si f m) = m
type Event ( STUB e st si f m) Source #
Instance details

Defined in Control.State.Transition.Extended

type Event ( STUB e st si f m) = Void
type PredicateFailure ( STUB e st si f m) Source #
Instance details

Defined in Control.State.Transition.Extended

type PredicateFailure ( STUB e st si f m) = f

class ( STS sub, BaseM sub ~ BaseM super) => Embed sub super where Source #

Embed one STS within another.

Minimal complete definition

wrapFailed

Methods

wrapFailed :: PredicateFailure sub -> PredicateFailure super Source #

Wrap a predicate failure of the subsystem in a failure of the super-system.

wrapEvent :: Event sub -> Event super Source #

(?!) :: Bool -> PredicateFailure sts -> Rule sts ctx () infix 1 Source #

Oh noes!

This takes a condition (a boolean expression) and a failure and results in a clause which will throw that failure if the condition fails.

(?!:) :: Either e () -> (e -> PredicateFailure sts) -> Rule sts ctx () Source #

Oh noes with an explanation

We interpret this as "What?" "No!" "Because:"

validateTrans Source #

Arguments

:: (e -> PredicateFailure sts)

Transformation function for all errors

-> Validation ( NonEmpty e) ()
-> Rule sts ctx ()

Same as validation , except with ability to transform opaque failures into PredicateFailure s with a help of supplied function.

validateTransLabeled Source #

Arguments

:: (e -> PredicateFailure sts)

Transformation function for all errors

-> NonEmpty Label

Supply a list of labels to be used as filters when STS is executed

-> Validation ( NonEmpty e) ()

Actual validations to be executed

-> Rule sts ctx ()

Same as validation , except with ability to translate opaque failures into PredicateFailure s with a help of supplied function.

type Label = String Source #

Label for a predicate. This can be used to control which predicates get run.

type family EventReturnType ep sts a :: Type where ... Source #

labeled :: NonEmpty Label -> Rule sts ctx () -> Rule sts ctx () Source #

Labeled clause. This will only be executed if the interpreter is set to execute clauses with this label.

labeledPred :: NonEmpty Label -> Bool -> PredicateFailure sts -> Rule sts ctx () Source #

Labeled predicate. This may be used to control which predicates are run using ValidateSuchThat .

labeledPredE :: NonEmpty Label -> Either e () -> (e -> PredicateFailure sts) -> Rule sts ctx () Source #

Labeled predicate with an explanation

ifFailureFree :: Rule sts rtype a -> Rule sts rtype a -> Rule sts rtype a Source #

whenFailureFree :: Rule sts rtype () -> Rule sts rtype () Source #

judgmentContext :: Rule sts rtype ( RuleContext rtype sts) Source #

Get the judgment context

trans :: Embed sub super => RuleContext rtype sub -> Rule super rtype ( State sub) Source #

mapEventReturn :: forall ep sts a b. EventReturnTypeRep ep => (a -> b) -> EventReturnType ep sts a -> EventReturnType ep sts b Source #

Map over an arbitrary EventReturnType .

Apply STS

data ValidationPolicy Source #

Control which predicates are evaluated during rule processing.

data ApplySTSOpts ep Source #

Constructors

ApplySTSOpts

Fields

applySTSOpts :: forall s m rtype ep. ( STS s, RuleTypeRep rtype, m ~ BaseM s) => ApplySTSOpts ep -> RuleContext rtype s -> m ( EventReturnType ep s ( State s, [ PredicateFailure s])) Source #

Apply an STS with options. Note that this returns both the final state and the list of predicate failures.

reapplySTS :: forall s m rtype. ( STS s, RuleTypeRep rtype, m ~ BaseM s) => RuleContext rtype s -> m ( State s) Source #

Re-apply an STS.

It is assumed that the caller of this function has previously applied this STS, and can guarantee that it completed successfully. No predicates or assertions will be checked when calling this function.

Exported to allow running rules independently

applyRuleInternal Source #

Arguments

:: forall (ep :: EventPolicy ) s m rtype. ( STS s, RuleTypeRep rtype, m ~ BaseM s)
=> IsFailing

We need to know if the current STS incurred at least one PredicateFailure. This is necessary because applyRuleInternal is called recursively through the goSTS argument, which will not have access to any of the predicate failures occured in other branches of STS rule execusion tree.

-> SingEP ep
-> ValidationPolicy
-> (IsFailing -> STSInterpreter ep)

Interpreter for subsystems

-> RuleContext rtype s
-> Rule s rtype ( State s)
-> m ( EventReturnType ep s ( State s, [ PredicateFailure s]))

Apply a rule even if its predicates fail.

If the rule successfully applied, the list of predicate failures will be empty.

type RuleInterpreter ep = forall s m rtype. ( STS s, RuleTypeRep rtype, m ~ BaseM s) => RuleContext rtype s -> Rule s rtype ( State s) -> m ( EventReturnType ep s ( State s, [ PredicateFailure s])) Source #

type STSInterpreter ep = forall s m rtype. ( STS s, RuleTypeRep rtype, m ~ BaseM s) => RuleContext rtype s -> m ( EventReturnType ep s ( State s, [ PredicateFailure s])) Source #

Random thing

newtype Threshold a Source #

This can be used to specify predicate failures in STS rules where a value is beyond a certain threshold.

TODO move this somewhere more sensible

Constructors

Threshold a

Instances

Instances details
Eq a => Eq ( Threshold a) Source #
Instance details

Defined in Control.State.Transition.Extended

Data a => Data ( Threshold a) Source #
Instance details

Defined in Control.State.Transition.Extended

Methods

gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> Threshold a -> c ( Threshold a) Source #

gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c ( Threshold a) Source #

toConstr :: Threshold a -> Constr Source #

dataTypeOf :: Threshold a -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c ( Threshold a)) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c ( Threshold a)) Source #

gmapT :: ( forall b. Data b => b -> b) -> Threshold a -> Threshold a Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> Threshold a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> Threshold a -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> Threshold a -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> Threshold a -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> Threshold a -> m ( Threshold a) Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> Threshold a -> m ( Threshold a) Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> Threshold a -> m ( Threshold a) Source #

Ord a => Ord ( Threshold a) Source #
Instance details

Defined in Control.State.Transition.Extended

Show a => Show ( Threshold a) Source #
Instance details

Defined in Control.State.Transition.Extended

NoThunks a => NoThunks ( Threshold a) Source #
Instance details

Defined in Control.State.Transition.Extended

sfor_ :: ( Foldable t, Applicative f) => t a -> (a -> f b) -> f () Source #

sfor_ is straverse_ with its arguments flipped. For a version that doesn't ignore the results see for .

>>> sfor_ ([1..4] :: [Int]) print
1
2
3
4