{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}

-- | Simple state transition system over the Identity monad.
module Control.State.Transition.Simple
  ( applySTSIndifferently,
    applySTS,
    module Extended,
  )
where

import Control.Monad.Identity (Identity (..))
import Control.State.Transition.Extended as Extended hiding (applySTS, applySTSIndifferently)
import qualified Control.State.Transition.Extended as X

applySTSIndifferently ::
  forall s rtype.
  (STS s, RuleTypeRep rtype, Identity ~ BaseM s) =>
  RuleContext rtype s ->
  (State s, [PredicateFailure s])
applySTSIndifferently :: RuleContext rtype s -> (State s, [PredicateFailure s])
applySTSIndifferently RuleContext rtype s
ctx = Identity (State s, [PredicateFailure s])
-> (State s, [PredicateFailure s])
forall a. Identity a -> a
runIdentity (Identity (State s, [PredicateFailure s])
 -> (State s, [PredicateFailure s]))
-> Identity (State s, [PredicateFailure s])
-> (State s, [PredicateFailure s])
forall a b. (a -> b) -> a -> b
$ RuleContext rtype s -> Identity (State s, [PredicateFailure s])
forall s (m :: * -> *) (rtype :: RuleType).
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
RuleContext rtype s -> m (State s, [PredicateFailure s])
X.applySTSIndifferently RuleContext rtype s
ctx

applySTS ::
  forall s rtype.
  (STS s, RuleTypeRep rtype, BaseM s ~ Identity) =>
  RuleContext rtype s ->
  Either [PredicateFailure s] (State s)
applySTS :: RuleContext rtype s -> Either [PredicateFailure s] (State s)
applySTS RuleContext rtype s
ctx = Identity (Either [PredicateFailure s] (State s))
-> Either [PredicateFailure s] (State s)
forall a. Identity a -> a
runIdentity (Identity (Either [PredicateFailure s] (State s))
 -> Either [PredicateFailure s] (State s))
-> Identity (Either [PredicateFailure s] (State s))
-> Either [PredicateFailure s] (State s)
forall a b. (a -> b) -> a -> b
$ RuleContext rtype s
-> Identity (Either [PredicateFailure s] (State s))
forall s (m :: * -> *) (rtype :: RuleType).
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
RuleContext rtype s -> m (Either [PredicateFailure s] (State s))
X.applySTS RuleContext rtype s
ctx