{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Logic.Ltl
(
Ltl (..),
somewhere,
everywhere,
there,
LtlAST,
modifyLtl,
InterpretLtlHigherOrder (..),
LtlInterpHigherOrder (..),
nowLaterList,
nowLaterSplit,
LtlInstanceKind (..),
InterpretEffectsLtl (..),
interpretLtlAST,
interpretLtlASTWithInitialFormulas,
)
where
import Control.Arrow
import Control.Monad
import Data.Functor.Const
import Data.Kind
import Effect
import Effect.Internal
import Logic.SingleStep
data Ltl a
=
LtlTruth
|
LtlFalsity
|
LtlAtom a
|
LtlOr (Ltl a) (Ltl a)
|
LtlAnd (Ltl a) (Ltl a)
|
LtlNext (Ltl a)
|
LtlUntil (Ltl a) (Ltl a)
|
LtlRelease (Ltl a) (Ltl a)
deriving (Int -> Ltl a -> ShowS
[Ltl a] -> ShowS
Ltl a -> String
(Int -> Ltl a -> ShowS)
-> (Ltl a -> String) -> ([Ltl a] -> ShowS) -> Show (Ltl a)
forall a. Show a => Int -> Ltl a -> ShowS
forall a. Show a => [Ltl a] -> ShowS
forall a. Show a => Ltl a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Ltl a -> ShowS
showsPrec :: Int -> Ltl a -> ShowS
$cshow :: forall a. Show a => Ltl a -> String
show :: Ltl a -> String
$cshowList :: forall a. Show a => [Ltl a] -> ShowS
showList :: [Ltl a] -> ShowS
Show)
somewhere :: a -> Ltl a
somewhere :: forall a. a -> Ltl a
somewhere a
a = Ltl a
forall a. Ltl a
LtlTruth Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
`LtlUntil` a -> Ltl a
forall a. a -> Ltl a
LtlAtom a
a
everywhere :: a -> Ltl a
everywhere :: forall a. a -> Ltl a
everywhere a
a = Ltl a
forall a. Ltl a
LtlFalsity Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
`LtlRelease` a -> Ltl a
forall a. a -> Ltl a
LtlAtom a
a
there :: Integer -> Ltl a -> Ltl a
there :: forall a. Integer -> Ltl a -> Ltl a
there Integer
0 = Ltl a -> Ltl a
forall a. a -> a
id
there Integer
n = Ltl a -> Ltl a
forall a. Ltl a -> Ltl a
LtlNext (Ltl a -> Ltl a) -> (Ltl a -> Ltl a) -> Ltl a -> Ltl a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Ltl a -> Ltl a
forall a. Integer -> Ltl a -> Ltl a
there (Integer
n Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
1)
data LtlEffect mod (m :: Type -> Type) a where
ModifyLtl :: Ltl mod -> m a -> LtlEffect mod m a
type LtlAST mod ops = AST (LtlEffect mod ': ops)
modifyLtl :: Ltl mod -> LtlAST mod ops a -> LtlAST mod ops a
modifyLtl :: forall mod (ops :: [(* -> *) -> * -> *]) a.
Ltl mod -> LtlAST mod ops a -> LtlAST mod ops a
modifyLtl Ltl mod
x LtlAST mod ops a
acts = LtlEffect mod (AST (LtlEffect mod : ops)) a -> LtlAST mod ops a
forall (op :: (* -> *) -> * -> *) (ops :: [(* -> *) -> * -> *]) a.
EffectInject op ops =>
op (AST ops) a -> AST ops a
astInject (LtlEffect mod (AST (LtlEffect mod : ops)) a -> LtlAST mod ops a)
-> LtlEffect mod (AST (LtlEffect mod : ops)) a -> LtlAST mod ops a
forall a b. (a -> b) -> a -> b
$ Ltl mod
-> LtlAST mod ops a -> LtlEffect mod (AST (LtlEffect mod : ops)) a
forall mod (m :: * -> *) a. Ltl mod -> m a -> LtlEffect mod m a
ModifyLtl Ltl mod
x LtlAST mod ops a
acts
instance
{-# OVERLAPPING #-}
(MonadPlus m) =>
InterpretEffectStateful (Const [Ltl mod]) m (LtlEffect mod)
where
interpretEffectStateful :: forall (ops :: [(* -> *) -> * -> *]) x a.
(forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x
-> LtlEffect mod (AST ops) a
-> m (a, Const [Ltl mod] x)
interpretEffectStateful forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y)
evalActs Const [Ltl mod] x
ltls (ModifyLtl Ltl mod
ltl AST ops a
acts) = do
(a
a, Const [Ltl mod]
ltls') <- Const [Ltl mod] Any -> AST ops a -> m (a, Const [Ltl mod] Any)
forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y)
evalActs ([Ltl mod] -> Const [Ltl mod] Any
forall {k} a (b :: k). a -> Const a b
Const ([Ltl mod] -> Const [Ltl mod] Any)
-> [Ltl mod] -> Const [Ltl mod] Any
forall a b. (a -> b) -> a -> b
$ Ltl mod
ltl Ltl mod -> [Ltl mod] -> [Ltl mod]
forall a. a -> [a] -> [a]
: Const [Ltl mod] x -> [Ltl mod]
forall {k} a (b :: k). Const a b -> a
getConst Const [Ltl mod] x
ltls) AST ops a
acts
if Ltl mod -> Bool
forall a. Ltl a -> Bool
finished (Ltl mod -> Bool) -> ([Ltl mod] -> Ltl mod) -> [Ltl mod] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Ltl mod] -> Ltl mod
forall a. HasCallStack => [a] -> a
head ([Ltl mod] -> Bool) -> [Ltl mod] -> Bool
forall a b. (a -> b) -> a -> b
$ [Ltl mod]
ltls'
then (a, Const [Ltl mod] x) -> m (a, Const [Ltl mod] x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, [Ltl mod] -> Const [Ltl mod] x
forall {k} a (b :: k). a -> Const a b
Const ([Ltl mod] -> Const [Ltl mod] x) -> [Ltl mod] -> Const [Ltl mod] x
forall a b. (a -> b) -> a -> b
$ [Ltl mod] -> [Ltl mod]
forall a. HasCallStack => [a] -> [a]
tail [Ltl mod]
ltls')
else m (a, Const [Ltl mod] x)
forall a. m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
class InterpretLtlHigherOrder (mod :: Type) (m :: Type -> Type) (op :: Effect) where
interpretLtlHigherOrder :: op (AST ops) a -> LtlInterpHigherOrder mod m ops a
data LtlInterpHigherOrder (mod :: Type) (m :: Type -> Type) (ops :: [Effect]) (a :: Type) where
Direct :: ModInterp mod m a -> LtlInterpHigherOrder mod m ops a
Nested ::
( (forall b. [Ltl mod] -> AST ops b -> m (b, [Ltl mod])) ->
[Ltl mod] ->
m (Maybe (a, [Ltl mod]))
) ->
LtlInterpHigherOrder mod m ops a
data LtlInstanceKind = InterpretModTag | InterpretLtlHigherOrderTag | InterpretEffectStatefulTag
data InterpretEffectsLtlConstraintList (mod :: Type) (m :: Type -> Type) (tags :: [LtlInstanceKind]) (ops :: [Effect]) where
InterpretEffectsLtlNil :: InterpretEffectsLtlConstraintList mod m '[] '[]
InterpretEffectsLtlFirstorder ::
(InterpretEffect m op, InterpretMod mod m op) =>
InterpretEffectsLtlConstraintList mod m tags ops ->
InterpretEffectsLtlConstraintList mod m (InterpretModTag ': tags) (op ': ops)
InterpretEffectsLtlHigherorder ::
(InterpretEffect m op, InterpretLtlHigherOrder mod m op) =>
InterpretEffectsLtlConstraintList mod m tags ops ->
InterpretEffectsLtlConstraintList mod m (InterpretLtlHigherOrderTag ': tags) (op ': ops)
InterpretEffectsLtlEffectStateful ::
(InterpretEffectStateful (Const [Ltl mod]) m op) =>
InterpretEffectsLtlConstraintList mod m tags ops ->
InterpretEffectsLtlConstraintList mod m (InterpretEffectStatefulTag ': tags) (op ': ops)
class InterpretEffectsLtl (mod :: Type) (m :: Type -> Type) (tags :: [LtlInstanceKind]) (ops :: [Effect]) where
interpretEffectsLtl :: InterpretEffectsLtlConstraintList mod m tags ops
instance InterpretEffectsLtl mod m '[] '[] where
interpretEffectsLtl :: InterpretEffectsLtlConstraintList mod m '[] '[]
interpretEffectsLtl = InterpretEffectsLtlConstraintList mod m '[] '[]
forall mod (m :: * -> *).
InterpretEffectsLtlConstraintList mod m '[] '[]
InterpretEffectsLtlNil
instance (InterpretEffect m op, InterpretMod mod m op, InterpretEffectsLtl mod m tags ops) => InterpretEffectsLtl mod m (InterpretModTag ': tags) (op ': ops) where
interpretEffectsLtl :: InterpretEffectsLtlConstraintList
mod m ('InterpretModTag : tags) (op : ops)
interpretEffectsLtl = InterpretEffectsLtlConstraintList mod m tags ops
-> InterpretEffectsLtlConstraintList
mod m ('InterpretModTag : tags) (op : ops)
forall (m :: * -> *) (op :: (* -> *) -> * -> *) mod
(tags :: [LtlInstanceKind]) (ops :: [(* -> *) -> * -> *]).
(InterpretEffect m op, InterpretMod mod m op) =>
InterpretEffectsLtlConstraintList mod m tags ops
-> InterpretEffectsLtlConstraintList
mod m ('InterpretModTag : tags) (op : ops)
InterpretEffectsLtlFirstorder InterpretEffectsLtlConstraintList mod m tags ops
forall mod (m :: * -> *) (tags :: [LtlInstanceKind])
(ops :: [(* -> *) -> * -> *]).
InterpretEffectsLtl mod m tags ops =>
InterpretEffectsLtlConstraintList mod m tags ops
interpretEffectsLtl
instance (InterpretEffect m op, InterpretLtlHigherOrder mod m op, InterpretEffectsLtl mod m tags ops) => InterpretEffectsLtl mod m (InterpretLtlHigherOrderTag ': tags) (op ': ops) where
interpretEffectsLtl :: InterpretEffectsLtlConstraintList
mod m ('InterpretLtlHigherOrderTag : tags) (op : ops)
interpretEffectsLtl = InterpretEffectsLtlConstraintList mod m tags ops
-> InterpretEffectsLtlConstraintList
mod m ('InterpretLtlHigherOrderTag : tags) (op : ops)
forall (m :: * -> *) (op :: (* -> *) -> * -> *) mod
(tags :: [LtlInstanceKind]) (ops :: [(* -> *) -> * -> *]).
(InterpretEffect m op, InterpretLtlHigherOrder mod m op) =>
InterpretEffectsLtlConstraintList mod m tags ops
-> InterpretEffectsLtlConstraintList
mod m ('InterpretLtlHigherOrderTag : tags) (op : ops)
InterpretEffectsLtlHigherorder InterpretEffectsLtlConstraintList mod m tags ops
forall mod (m :: * -> *) (tags :: [LtlInstanceKind])
(ops :: [(* -> *) -> * -> *]).
InterpretEffectsLtl mod m tags ops =>
InterpretEffectsLtlConstraintList mod m tags ops
interpretEffectsLtl
instance (InterpretEffectStateful (Const [Ltl mod]) m op, InterpretEffectsLtl mod m tags ops) => InterpretEffectsLtl mod m (InterpretEffectStatefulTag ': tags) (op ': ops) where
interpretEffectsLtl :: InterpretEffectsLtlConstraintList
mod m ('InterpretEffectStatefulTag : tags) (op : ops)
interpretEffectsLtl = InterpretEffectsLtlConstraintList mod m tags ops
-> InterpretEffectsLtlConstraintList
mod m ('InterpretEffectStatefulTag : tags) (op : ops)
forall mod (m :: * -> *) (op :: (* -> *) -> * -> *)
(tags :: [LtlInstanceKind]) (ops :: [(* -> *) -> * -> *]).
InterpretEffectStateful (Const [Ltl mod]) m op =>
InterpretEffectsLtlConstraintList mod m tags ops
-> InterpretEffectsLtlConstraintList
mod m ('InterpretEffectStatefulTag : tags) (op : ops)
InterpretEffectsLtlEffectStateful InterpretEffectsLtlConstraintList mod m tags ops
forall mod (m :: * -> *) (tags :: [LtlInstanceKind])
(ops :: [(* -> *) -> * -> *]).
InterpretEffectsLtl mod m tags ops =>
InterpretEffectsLtlConstraintList mod m tags ops
interpretEffectsLtl
interpretLtlAST ::
forall tags mod m ops a.
(Semigroup mod, MonadPlus m, InterpretEffectsLtl mod m tags ops) =>
LtlAST mod ops a ->
m a
interpretLtlAST :: forall (tags :: [LtlInstanceKind]) mod (m :: * -> *)
(ops :: [(* -> *) -> * -> *]) a.
(Semigroup mod, MonadPlus m, InterpretEffectsLtl mod m tags ops) =>
LtlAST mod ops a -> m a
interpretLtlAST = forall (tags :: [LtlInstanceKind]) mod (m :: * -> *)
(ops :: [(* -> *) -> * -> *]) a.
(Semigroup mod, MonadPlus m, InterpretEffectsLtl mod m tags ops) =>
[Ltl mod] -> LtlAST mod ops a -> m a
interpretLtlASTWithInitialFormulas @tags []
interpretLtlASTWithInitialFormulas ::
forall tags mod m ops a.
(Semigroup mod, MonadPlus m, InterpretEffectsLtl mod m tags ops) =>
[Ltl mod] ->
LtlAST mod ops a ->
m a
interpretLtlASTWithInitialFormulas :: forall (tags :: [LtlInstanceKind]) mod (m :: * -> *)
(ops :: [(* -> *) -> * -> *]) a.
(Semigroup mod, MonadPlus m, InterpretEffectsLtl mod m tags ops) =>
[Ltl mod] -> LtlAST mod ops a -> m a
interpretLtlASTWithInitialFormulas [Ltl mod]
ltls LtlAST mod ops a
acts = do
(a
a, [Ltl mod]
finals) <- (Const [Ltl mod] Any -> [Ltl mod])
-> (a, Const [Ltl mod] Any) -> (a, [Ltl mod])
forall b c d. (b -> c) -> (d, b) -> (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second Const [Ltl mod] Any -> [Ltl mod]
forall {k} a (b :: k). Const a b -> a
getConst ((a, Const [Ltl mod] Any) -> (a, [Ltl mod]))
-> m (a, Const [Ltl mod] Any) -> m (a, [Ltl mod])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> InterpretEffectsLtlConstraintList
mod m ('InterpretEffectStatefulTag : tags) (LtlEffect mod : ops)
-> Const [Ltl mod] Any
-> LtlAST mod ops a
-> m (a, Const [Ltl mod] Any)
forall mod (m :: * -> *) (tags :: [LtlInstanceKind])
(ops :: [(* -> *) -> * -> *]) x a.
(Semigroup mod, MonadPlus m) =>
InterpretEffectsLtlConstraintList mod m tags ops
-> Const [Ltl mod] x -> AST ops a -> m (a, Const [Ltl mod] x)
interpretASTLtlInternal InterpretEffectsLtlConstraintList
mod m ('InterpretEffectStatefulTag : tags) (LtlEffect mod : ops)
constraintList ([Ltl mod] -> Const [Ltl mod] Any
forall {k} a (b :: k). a -> Const a b
Const [Ltl mod]
ltls) LtlAST mod ops a
acts
if (Ltl mod -> Bool) -> [Ltl mod] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Ltl mod -> Bool
forall a. Ltl a -> Bool
finished [Ltl mod]
finals
then a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
else m a
forall a. m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
where
constraintList :: InterpretEffectsLtlConstraintList
mod m ('InterpretEffectStatefulTag : tags) (LtlEffect mod : ops)
constraintList = forall mod (m :: * -> *) (tags :: [LtlInstanceKind])
(ops :: [(* -> *) -> * -> *]).
InterpretEffectsLtl mod m tags ops =>
InterpretEffectsLtlConstraintList mod m tags ops
interpretEffectsLtl @mod @m @(InterpretEffectStatefulTag ': tags)
interpretASTLtlInternal ::
(Semigroup mod, MonadPlus m) =>
InterpretEffectsLtlConstraintList mod m tags ops ->
Const [Ltl mod] x ->
AST ops a ->
m (a, Const [Ltl mod] x)
interpretASTLtlInternal :: forall mod (m :: * -> *) (tags :: [LtlInstanceKind])
(ops :: [(* -> *) -> * -> *]) x a.
(Semigroup mod, MonadPlus m) =>
InterpretEffectsLtlConstraintList mod m tags ops
-> Const [Ltl mod] x -> AST ops a -> m (a, Const [Ltl mod] x)
interpretASTLtlInternal InterpretEffectsLtlConstraintList mod m tags ops
cs Const [Ltl mod] x
x =
(forall b.
Const [Ltl mod] x
-> Fixpoint (JoinedEffects ops) Freer b
-> m (b, Const [Ltl mod] x))
-> Const [Ltl mod] x
-> Freer (Fixpoint (JoinedEffects ops) Freer) a
-> m (a, Const [Ltl mod] x)
forall a.
(forall b.
Const [Ltl mod] x
-> Fixpoint (JoinedEffects ops) Freer b
-> m (b, Const [Ltl mod] x))
-> Const [Ltl mod] x
-> Freer (Fixpoint (JoinedEffects ops) Freer) a
-> m (a, Const [Ltl mod] x)
forall x (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
(m :: * -> *) a.
InterpretOneLayerState x f g m =>
(forall b. x -> Fixpoint g f b -> m (b, x))
-> x -> f (Fixpoint g f) a -> m (a, x)
interpretOneLayerState
( \Const [Ltl mod] x
x' Fixpoint (JoinedEffects ops) Freer b
acts ->
InterpretEffectsLtlConstraintList mod m tags ops
-> (forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x
-> JoinedEffects ops (AST ops) b
-> m (b, Const [Ltl mod] x)
forall mod (m :: * -> *) (tags :: [LtlInstanceKind])
(ops :: [(* -> *) -> * -> *]) (allOps :: [(* -> *) -> * -> *]) x a.
(Semigroup mod, MonadPlus m) =>
InterpretEffectsLtlConstraintList mod m tags ops
-> (forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x
-> JoinedEffects ops (AST allOps) a
-> m (a, Const [Ltl mod] x)
interpretJoinedEffectsLtl
InterpretEffectsLtlConstraintList mod m tags ops
cs
(InterpretEffectsLtlConstraintList mod m tags ops
-> Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y)
forall mod (m :: * -> *) (tags :: [LtlInstanceKind])
(ops :: [(* -> *) -> * -> *]) x a.
(Semigroup mod, MonadPlus m) =>
InterpretEffectsLtlConstraintList mod m tags ops
-> Const [Ltl mod] x -> AST ops a -> m (a, Const [Ltl mod] x)
interpretASTLtlInternal InterpretEffectsLtlConstraintList mod m tags ops
cs)
Const [Ltl mod] x
x'
(Fixpoint (JoinedEffects ops) Freer b
-> JoinedEffects ops (AST ops) b
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *) a.
Fixpoint f g a -> f (Fixpoint g f) a
unFixpoint Fixpoint (JoinedEffects ops) Freer b
acts)
)
Const [Ltl mod] x
x
(Freer (Fixpoint (JoinedEffects ops) Freer) a
-> m (a, Const [Ltl mod] x))
-> (AST ops a -> Freer (Fixpoint (JoinedEffects ops) Freer) a)
-> AST ops a
-> m (a, Const [Ltl mod] x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AST ops a -> Freer (Fixpoint (JoinedEffects ops) Freer) a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *) a.
Fixpoint f g a -> f (Fixpoint g f) a
unFixpoint
interpretJoinedEffectsLtl ::
(Semigroup mod, MonadPlus m) =>
InterpretEffectsLtlConstraintList mod m tags ops ->
(forall b y. Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)) ->
Const [Ltl mod] x ->
JoinedEffects ops (AST allOps) a ->
m (a, Const [Ltl mod] x)
interpretJoinedEffectsLtl :: forall mod (m :: * -> *) (tags :: [LtlInstanceKind])
(ops :: [(* -> *) -> * -> *]) (allOps :: [(* -> *) -> * -> *]) x a.
(Semigroup mod, MonadPlus m) =>
InterpretEffectsLtlConstraintList mod m tags ops
-> (forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x
-> JoinedEffects ops (AST allOps) a
-> m (a, Const [Ltl mod] x)
interpretJoinedEffectsLtl InterpretEffectsLtlConstraintList mod m tags ops
InterpretEffectsLtlNil forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
_ Const [Ltl mod] x
_ JoinedEffects ops (AST allOps) a
op = case JoinedEffects ops (AST allOps) a
op of {}
interpretJoinedEffectsLtl (InterpretEffectsLtlFirstorder InterpretEffectsLtlConstraintList mod m tags ops
_) forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
evalAST Const [Ltl mod] x
x (JoinedEffectsHere op (AST allOps) a
op) =
(forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x
-> op (AST allOps) a
-> m (a, Const [Ltl mod] x)
forall mod (m :: * -> *) (op :: (* -> *) -> * -> *)
(ops :: [(* -> *) -> * -> *]) x a.
(Semigroup mod, MonadPlus m, InterpretEffect m op,
InterpretMod mod m op) =>
(forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x -> op (AST ops) a -> m (a, Const [Ltl mod] x)
interpretEffectStatefulFromLtl Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
evalAST Const [Ltl mod] x
x op (AST allOps) a
op
interpretJoinedEffectsLtl (InterpretEffectsLtlFirstorder InterpretEffectsLtlConstraintList mod m tags ops
cs) forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
evalAST Const [Ltl mod] x
x (JoinedEffectsThere JoinedEffects ops1 (AST allOps) a
op) =
InterpretEffectsLtlConstraintList mod m tags ops
-> (forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x
-> JoinedEffects ops (AST allOps) a
-> m (a, Const [Ltl mod] x)
forall mod (m :: * -> *) (tags :: [LtlInstanceKind])
(ops :: [(* -> *) -> * -> *]) (allOps :: [(* -> *) -> * -> *]) x a.
(Semigroup mod, MonadPlus m) =>
InterpretEffectsLtlConstraintList mod m tags ops
-> (forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x
-> JoinedEffects ops (AST allOps) a
-> m (a, Const [Ltl mod] x)
interpretJoinedEffectsLtl InterpretEffectsLtlConstraintList mod m tags ops
cs Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
evalAST Const [Ltl mod] x
x JoinedEffects ops (AST allOps) a
JoinedEffects ops1 (AST allOps) a
op
interpretJoinedEffectsLtl (InterpretEffectsLtlHigherorder InterpretEffectsLtlConstraintList mod m tags ops
_) forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
evalAST Const [Ltl mod] x
x (JoinedEffectsHere op (AST allOps) a
op) =
(forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x
-> op (AST allOps) a
-> m (a, Const [Ltl mod] x)
forall mod (m :: * -> *) (op :: (* -> *) -> * -> *)
(ops :: [(* -> *) -> * -> *]) x a.
(Semigroup mod, MonadPlus m, InterpretEffect m op,
InterpretLtlHigherOrder mod m op) =>
(forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x -> op (AST ops) a -> m (a, Const [Ltl mod] x)
interpretEffectStatefulFromLtlHigherOrder Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
evalAST Const [Ltl mod] x
x op (AST allOps) a
op
interpretJoinedEffectsLtl (InterpretEffectsLtlHigherorder InterpretEffectsLtlConstraintList mod m tags ops
cs) forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
evalAST Const [Ltl mod] x
x (JoinedEffectsThere JoinedEffects ops1 (AST allOps) a
op) =
InterpretEffectsLtlConstraintList mod m tags ops
-> (forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x
-> JoinedEffects ops (AST allOps) a
-> m (a, Const [Ltl mod] x)
forall mod (m :: * -> *) (tags :: [LtlInstanceKind])
(ops :: [(* -> *) -> * -> *]) (allOps :: [(* -> *) -> * -> *]) x a.
(Semigroup mod, MonadPlus m) =>
InterpretEffectsLtlConstraintList mod m tags ops
-> (forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x
-> JoinedEffects ops (AST allOps) a
-> m (a, Const [Ltl mod] x)
interpretJoinedEffectsLtl InterpretEffectsLtlConstraintList mod m tags ops
cs Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
evalAST Const [Ltl mod] x
x JoinedEffects ops (AST allOps) a
JoinedEffects ops1 (AST allOps) a
op
interpretJoinedEffectsLtl (InterpretEffectsLtlEffectStateful InterpretEffectsLtlConstraintList mod m tags ops
_) forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
evalAST Const [Ltl mod] x
x (JoinedEffectsHere op (AST allOps) a
op) =
(forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x
-> op (AST allOps) a
-> m (a, Const [Ltl mod] x)
forall (ops :: [(* -> *) -> * -> *]) x a.
(forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x -> op (AST ops) a -> m (a, Const [Ltl mod] x)
forall (t :: * -> *) (m :: * -> *) (op :: (* -> *) -> * -> *)
(ops :: [(* -> *) -> * -> *]) x a.
InterpretEffectStateful t m op =>
(forall b y. t y -> AST ops b -> m (b, t y))
-> t x -> op (AST ops) a -> m (a, t x)
interpretEffectStateful Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
evalAST Const [Ltl mod] x
x op (AST allOps) a
op
interpretJoinedEffectsLtl (InterpretEffectsLtlEffectStateful InterpretEffectsLtlConstraintList mod m tags ops
cs) forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
evalAST Const [Ltl mod] x
x (JoinedEffectsThere JoinedEffects ops1 (AST allOps) a
op) =
InterpretEffectsLtlConstraintList mod m tags ops
-> (forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x
-> JoinedEffects ops (AST allOps) a
-> m (a, Const [Ltl mod] x)
forall mod (m :: * -> *) (tags :: [LtlInstanceKind])
(ops :: [(* -> *) -> * -> *]) (allOps :: [(* -> *) -> * -> *]) x a.
(Semigroup mod, MonadPlus m) =>
InterpretEffectsLtlConstraintList mod m tags ops
-> (forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x
-> JoinedEffects ops (AST allOps) a
-> m (a, Const [Ltl mod] x)
interpretJoinedEffectsLtl InterpretEffectsLtlConstraintList mod m tags ops
cs Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
forall b y.
Const [Ltl mod] y -> AST allOps b -> m (b, Const [Ltl mod] y)
evalAST Const [Ltl mod] x
x JoinedEffects ops (AST allOps) a
JoinedEffects ops1 (AST allOps) a
op
interpretEffectStatefulFromLtl ::
( Semigroup mod,
MonadPlus m,
InterpretEffect m op,
InterpretMod mod m op
) =>
(forall b y. Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y)) ->
Const [Ltl mod] x ->
op (AST ops) a ->
m (a, Const [Ltl mod] x)
interpretEffectStatefulFromLtl :: forall mod (m :: * -> *) (op :: (* -> *) -> * -> *)
(ops :: [(* -> *) -> * -> *]) x a.
(Semigroup mod, MonadPlus m, InterpretEffect m op,
InterpretMod mod m op) =>
(forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x -> op (AST ops) a -> m (a, Const [Ltl mod] x)
interpretEffectStatefulFromLtl forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y)
evalActs (Const [Ltl mod]
ltls) op (AST ops) a
op =
case op (AST ops) a -> ModInterp mod m a
forall (dummy :: [(* -> *) -> * -> *]) a.
op (AST dummy) a -> ModInterp mod m a
forall mod (m :: * -> *) (op :: (* -> *) -> * -> *)
(dummy :: [(* -> *) -> * -> *]) a.
InterpretMod mod m op =>
op (AST dummy) a -> ModInterp mod m a
interpretMod op (AST ops) a
op of
ModInterp mod m a
Invisible -> [Ltl mod] -> op (AST ops) a -> m (a, Const [Ltl mod] x)
interpretUnmodified [Ltl mod]
ltls op (AST ops) a
op
Visible mod -> m (Maybe a)
attempt ->
[m (a, Const [Ltl mod] x)] -> m (a, Const [Ltl mod] x)
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum ([m (a, Const [Ltl mod] x)] -> m (a, Const [Ltl mod] x))
-> [m (a, Const [Ltl mod] x)] -> m (a, Const [Ltl mod] x)
forall a b. (a -> b) -> a -> b
$
((Maybe mod, [Ltl mod]) -> m (a, Const [Ltl mod] x))
-> [(Maybe mod, [Ltl mod])] -> [m (a, Const [Ltl mod] x)]
forall a b. (a -> b) -> [a] -> [b]
map
( \(Maybe mod
now, [Ltl mod]
later) ->
case Maybe mod
now of
Maybe mod
Nothing -> [Ltl mod] -> op (AST ops) a -> m (a, Const [Ltl mod] x)
interpretUnmodified [Ltl mod]
later op (AST ops) a
op
Just mod
now' -> do
Maybe a
mA <- mod -> m (Maybe a)
attempt mod
now'
case Maybe a
mA of
Just a
a -> (a, Const [Ltl mod] x) -> m (a, Const [Ltl mod] x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, [Ltl mod] -> Const [Ltl mod] x
forall {k} a (b :: k). a -> Const a b
Const [Ltl mod]
later)
Maybe a
Nothing -> m (a, Const [Ltl mod] x)
forall a. m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
)
([Ltl mod] -> [(Maybe mod, [Ltl mod])]
forall a. Semigroup a => [Ltl a] -> [(Maybe a, [Ltl a])]
nowLaterList [Ltl mod]
ltls)
where
interpretUnmodified :: [Ltl mod] -> op (AST ops) a -> m (a, Const [Ltl mod] x)
interpretUnmodified [Ltl mod]
later op (AST ops) a
x =
(,[Ltl mod] -> Const [Ltl mod] x
forall {k} a (b :: k). a -> Const a b
Const [Ltl mod]
later)
(a -> (a, Const [Ltl mod] x)) -> m a -> m (a, Const [Ltl mod] x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall b. AST ops b -> m b) -> op (AST ops) a -> m a
forall (ops :: [(* -> *) -> * -> *]) a.
(forall b. AST ops b -> m b) -> op (AST ops) a -> m a
forall (m :: * -> *) (op :: (* -> *) -> * -> *)
(ops :: [(* -> *) -> * -> *]) a.
InterpretEffect m op =>
(forall b. AST ops b -> m b) -> op (AST ops) a -> m a
interpretEffect
(((b, Const [Ltl mod] Any) -> b)
-> m (b, Const [Ltl mod] Any) -> m b
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (b, Const [Ltl mod] Any) -> b
forall a b. (a, b) -> a
fst (m (b, Const [Ltl mod] Any) -> m b)
-> (AST ops b -> m (b, Const [Ltl mod] Any)) -> AST ops b -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const [Ltl mod] Any -> AST ops b -> m (b, Const [Ltl mod] Any)
forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y)
evalActs ([Ltl mod] -> Const [Ltl mod] Any
forall {k} a (b :: k). a -> Const a b
Const []))
op (AST ops) a
x
interpretEffectStatefulFromLtlHigherOrder ::
( Semigroup mod,
MonadPlus m,
InterpretEffect m op,
InterpretLtlHigherOrder mod m op
) =>
(forall b y. Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y)) ->
Const [Ltl mod] x ->
op (AST ops) a ->
m (a, Const [Ltl mod] x)
interpretEffectStatefulFromLtlHigherOrder :: forall mod (m :: * -> *) (op :: (* -> *) -> * -> *)
(ops :: [(* -> *) -> * -> *]) x a.
(Semigroup mod, MonadPlus m, InterpretEffect m op,
InterpretLtlHigherOrder mod m op) =>
(forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y))
-> Const [Ltl mod] x -> op (AST ops) a -> m (a, Const [Ltl mod] x)
interpretEffectStatefulFromLtlHigherOrder forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y)
evalActs (Const [Ltl mod]
ltls) op (AST ops) a
op =
case op (AST ops) a -> LtlInterpHigherOrder mod m ops a
forall (ops :: [(* -> *) -> * -> *]) a.
op (AST ops) a -> LtlInterpHigherOrder mod m ops a
forall mod (m :: * -> *) (op :: (* -> *) -> * -> *)
(ops :: [(* -> *) -> * -> *]) a.
InterpretLtlHigherOrder mod m op =>
op (AST ops) a -> LtlInterpHigherOrder mod m ops a
interpretLtlHigherOrder op (AST ops) a
op of
Direct ModInterp mod m a
inner -> case ModInterp mod m a
inner of
ModInterp mod m a
Invisible -> [Ltl mod] -> op (AST ops) a -> m (a, Const [Ltl mod] x)
interpretUnmodified [Ltl mod]
ltls op (AST ops) a
op
Visible mod -> m (Maybe a)
attempt ->
[m (a, Const [Ltl mod] x)] -> m (a, Const [Ltl mod] x)
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum ([m (a, Const [Ltl mod] x)] -> m (a, Const [Ltl mod] x))
-> [m (a, Const [Ltl mod] x)] -> m (a, Const [Ltl mod] x)
forall a b. (a -> b) -> a -> b
$
((Maybe mod, [Ltl mod]) -> m (a, Const [Ltl mod] x))
-> [(Maybe mod, [Ltl mod])] -> [m (a, Const [Ltl mod] x)]
forall a b. (a -> b) -> [a] -> [b]
map
( \(Maybe mod
now, [Ltl mod]
later) ->
case Maybe mod
now of
Maybe mod
Nothing -> [Ltl mod] -> op (AST ops) a -> m (a, Const [Ltl mod] x)
interpretUnmodified [Ltl mod]
later op (AST ops) a
op
Just mod
now' -> do
Maybe a
mA <- mod -> m (Maybe a)
attempt mod
now'
case Maybe a
mA of
Just a
a -> (a, Const [Ltl mod] x) -> m (a, Const [Ltl mod] x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, [Ltl mod] -> Const [Ltl mod] x
forall {k} a (b :: k). a -> Const a b
Const [Ltl mod]
later)
Maybe a
Nothing -> m (a, Const [Ltl mod] x)
forall a. m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
)
([Ltl mod] -> [(Maybe mod, [Ltl mod])]
forall a. Semigroup a => [Ltl a] -> [(Maybe a, [Ltl a])]
nowLaterList [Ltl mod]
ltls)
Nested (forall b. [Ltl mod] -> AST ops b -> m (b, [Ltl mod]))
-> [Ltl mod] -> m (Maybe (a, [Ltl mod]))
nestFun -> do
Maybe (a, [Ltl mod])
mA <- (forall b. [Ltl mod] -> AST ops b -> m (b, [Ltl mod]))
-> [Ltl mod] -> m (Maybe (a, [Ltl mod]))
nestFun (\[Ltl mod]
x' AST ops b
ast -> (Const [Ltl mod] Any -> [Ltl mod])
-> (b, Const [Ltl mod] Any) -> (b, [Ltl mod])
forall b c d. (b -> c) -> (d, b) -> (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second Const [Ltl mod] Any -> [Ltl mod]
forall {k} a (b :: k). Const a b -> a
getConst ((b, Const [Ltl mod] Any) -> (b, [Ltl mod]))
-> m (b, Const [Ltl mod] Any) -> m (b, [Ltl mod])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Const [Ltl mod] Any -> AST ops b -> m (b, Const [Ltl mod] Any)
forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y)
evalActs ([Ltl mod] -> Const [Ltl mod] Any
forall {k} a (b :: k). a -> Const a b
Const [Ltl mod]
x') AST ops b
ast) [Ltl mod]
ltls
case Maybe (a, [Ltl mod])
mA of
Maybe (a, [Ltl mod])
Nothing -> m (a, Const [Ltl mod] x)
forall a. m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
Just (a
a, [Ltl mod]
ltls') -> (a, Const [Ltl mod] x) -> m (a, Const [Ltl mod] x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, [Ltl mod] -> Const [Ltl mod] x
forall {k} a (b :: k). a -> Const a b
Const [Ltl mod]
ltls')
where
interpretUnmodified :: [Ltl mod] -> op (AST ops) a -> m (a, Const [Ltl mod] x)
interpretUnmodified [Ltl mod]
later op (AST ops) a
x =
(,[Ltl mod] -> Const [Ltl mod] x
forall {k} a (b :: k). a -> Const a b
Const [Ltl mod]
later)
(a -> (a, Const [Ltl mod] x)) -> m a -> m (a, Const [Ltl mod] x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall b. AST ops b -> m b) -> op (AST ops) a -> m a
forall (ops :: [(* -> *) -> * -> *]) a.
(forall b. AST ops b -> m b) -> op (AST ops) a -> m a
forall (m :: * -> *) (op :: (* -> *) -> * -> *)
(ops :: [(* -> *) -> * -> *]) a.
InterpretEffect m op =>
(forall b. AST ops b -> m b) -> op (AST ops) a -> m a
interpretEffect
(((b, Const [Ltl mod] Any) -> b)
-> m (b, Const [Ltl mod] Any) -> m b
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (b, Const [Ltl mod] Any) -> b
forall a b. (a, b) -> a
fst (m (b, Const [Ltl mod] Any) -> m b)
-> (AST ops b -> m (b, Const [Ltl mod] Any)) -> AST ops b -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const [Ltl mod] Any -> AST ops b -> m (b, Const [Ltl mod] Any)
forall b y.
Const [Ltl mod] y -> AST ops b -> m (b, Const [Ltl mod] y)
evalActs ([Ltl mod] -> Const [Ltl mod] Any
forall {k} a (b :: k). a -> Const a b
Const []))
op (AST ops) a
x
nowLater :: (Semigroup a) => Ltl a -> [(Maybe a, Ltl a)]
nowLater :: forall a. Semigroup a => Ltl a -> [(Maybe a, Ltl a)]
nowLater Ltl a
LtlTruth = [(Maybe a
forall a. Maybe a
Nothing, Ltl a
forall a. Ltl a
LtlTruth)]
nowLater Ltl a
LtlFalsity = []
nowLater (LtlAtom a
g) = [(a -> Maybe a
forall a. a -> Maybe a
Just a
g, Ltl a
forall a. Ltl a
LtlTruth)]
nowLater (Ltl a
a `LtlOr` Ltl a
b) = Ltl a -> [(Maybe a, Ltl a)]
forall a. Semigroup a => Ltl a -> [(Maybe a, Ltl a)]
nowLater Ltl a
a [(Maybe a, Ltl a)] -> [(Maybe a, Ltl a)] -> [(Maybe a, Ltl a)]
forall a. [a] -> [a] -> [a]
++ Ltl a -> [(Maybe a, Ltl a)]
forall a. Semigroup a => Ltl a -> [(Maybe a, Ltl a)]
nowLater Ltl a
b
nowLater (Ltl a
a `LtlAnd` Ltl a
b) =
[ ( Maybe a
f Maybe a -> Maybe a -> Maybe a
forall a. Semigroup a => a -> a -> a
<> Maybe a
g,
Ltl a -> Ltl a
forall a. Ltl a -> Ltl a
ltlSimpl (Ltl a -> Ltl a) -> Ltl a -> Ltl a
forall a b. (a -> b) -> a -> b
$ Ltl a
c Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
`LtlAnd` Ltl a
d
)
| (Maybe a
f, Ltl a
c) <- Ltl a -> [(Maybe a, Ltl a)]
forall a. Semigroup a => Ltl a -> [(Maybe a, Ltl a)]
nowLater Ltl a
a,
(Maybe a
g, Ltl a
d) <- Ltl a -> [(Maybe a, Ltl a)]
forall a. Semigroup a => Ltl a -> [(Maybe a, Ltl a)]
nowLater Ltl a
b
]
nowLater (LtlNext Ltl a
a) = [(Maybe a
forall a. Maybe a
Nothing, Ltl a
a)]
nowLater (Ltl a
a `LtlUntil` Ltl a
b) =
Ltl a -> [(Maybe a, Ltl a)]
forall a. Semigroup a => Ltl a -> [(Maybe a, Ltl a)]
nowLater (Ltl a -> [(Maybe a, Ltl a)]) -> Ltl a -> [(Maybe a, Ltl a)]
forall a b. (a -> b) -> a -> b
$ Ltl a
b Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
`LtlOr` (Ltl a
a Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
`LtlAnd` Ltl a -> Ltl a
forall a. Ltl a -> Ltl a
LtlNext (Ltl a
a Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
`LtlUntil` Ltl a
b))
nowLater (Ltl a
a `LtlRelease` Ltl a
b) =
Ltl a -> [(Maybe a, Ltl a)]
forall a. Semigroup a => Ltl a -> [(Maybe a, Ltl a)]
nowLater (Ltl a -> [(Maybe a, Ltl a)]) -> Ltl a -> [(Maybe a, Ltl a)]
forall a b. (a -> b) -> a -> b
$ Ltl a
b Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
`LtlAnd` (Ltl a
a Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
`LtlOr` Ltl a -> Ltl a
forall a. Ltl a -> Ltl a
LtlNext (Ltl a
a Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
`LtlRelease` Ltl a
b))
finished :: Ltl a -> Bool
finished :: forall a. Ltl a -> Bool
finished Ltl a
LtlTruth = Bool
True
finished Ltl a
LtlFalsity = Bool
False
finished (LtlAtom a
_) = Bool
False
finished (Ltl a
a `LtlAnd` Ltl a
b) = Ltl a -> Bool
forall a. Ltl a -> Bool
finished Ltl a
a Bool -> Bool -> Bool
&& Ltl a -> Bool
forall a. Ltl a -> Bool
finished Ltl a
b
finished (Ltl a
a `LtlOr` Ltl a
b) = Ltl a -> Bool
forall a. Ltl a -> Bool
finished Ltl a
a Bool -> Bool -> Bool
|| Ltl a -> Bool
forall a. Ltl a -> Bool
finished Ltl a
b
finished (LtlNext Ltl a
_) = Bool
False
finished (LtlUntil Ltl a
_ Ltl a
_) = Bool
False
finished (LtlRelease Ltl a
_ Ltl a
_) = Bool
True
nowLaterList :: (Semigroup a) => [Ltl a] -> [(Maybe a, [Ltl a])]
nowLaterList :: forall a. Semigroup a => [Ltl a] -> [(Maybe a, [Ltl a])]
nowLaterList = [[(Maybe a, Ltl a)]] -> [(Maybe a, [Ltl a])]
forall {a} {a}. Monoid a => [[(a, a)]] -> [(a, [a])]
joinNowLaters ([[(Maybe a, Ltl a)]] -> [(Maybe a, [Ltl a])])
-> ([Ltl a] -> [[(Maybe a, Ltl a)]])
-> [Ltl a]
-> [(Maybe a, [Ltl a])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Ltl a -> [(Maybe a, Ltl a)]) -> [Ltl a] -> [[(Maybe a, Ltl a)]]
forall a b. (a -> b) -> [a] -> [b]
map Ltl a -> [(Maybe a, Ltl a)]
forall a. Semigroup a => Ltl a -> [(Maybe a, Ltl a)]
nowLater
where
joinNowLaters :: [[(a, a)]] -> [(a, [a])]
joinNowLaters [] = [(a
forall a. Monoid a => a
mempty, [])]
joinNowLaters ([(a, a)]
l : [[(a, a)]]
ls) =
[ (a
g a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
f, a
c a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
cs)
| (a
f, a
c) <- [(a, a)]
l,
(a
g, [a]
cs) <- [[(a, a)]] -> [(a, [a])]
joinNowLaters [[(a, a)]]
ls
]
nowLaterSplit ::
(Semigroup x, MonadPlus m) =>
m a ->
(x -> m (Maybe a)) ->
[Ltl x] ->
m (a, [Ltl x])
nowLaterSplit :: forall x (m :: * -> *) a.
(Semigroup x, MonadPlus m) =>
m a -> (x -> m (Maybe a)) -> [Ltl x] -> m (a, [Ltl x])
nowLaterSplit m a
defaultBehaviour x -> m (Maybe a)
applyMod [Ltl x]
formulas =
[m (a, [Ltl x])] -> m (a, [Ltl x])
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum ([m (a, [Ltl x])] -> m (a, [Ltl x]))
-> [m (a, [Ltl x])] -> m (a, [Ltl x])
forall a b. (a -> b) -> a -> b
$
((Maybe x, [Ltl x]) -> m (a, [Ltl x]))
-> [(Maybe x, [Ltl x])] -> [m (a, [Ltl x])]
forall a b. (a -> b) -> [a] -> [b]
map
( \(Maybe x
now, [Ltl x]
later) -> case Maybe x
now of
Maybe x
Nothing -> (,[Ltl x]
later) (a -> (a, [Ltl x])) -> m a -> m (a, [Ltl x])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
defaultBehaviour
Just x
x -> do
Maybe a
mA <- x -> m (Maybe a)
applyMod x
x
case Maybe a
mA of
Maybe a
Nothing -> m (a, [Ltl x])
forall a. m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
Just a
a -> (a, [Ltl x]) -> m (a, [Ltl x])
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, [Ltl x]
later)
)
([Ltl x] -> [(Maybe x, [Ltl x])]
forall a. Semigroup a => [Ltl a] -> [(Maybe a, [Ltl a])]
nowLaterList [Ltl x]
formulas)
ltlSimpl :: Ltl a -> Ltl a
ltlSimpl :: forall a. Ltl a -> Ltl a
ltlSimpl Ltl a
expr =
let (Ltl a
expr', Bool
progress) = Ltl a -> (Ltl a, Bool)
forall a. Ltl a -> (Ltl a, Bool)
simpl Ltl a
expr
in if Bool
progress then Ltl a
expr' else Ltl a
expr
where
simpl :: Ltl a -> (Ltl a, Bool)
simpl :: forall a. Ltl a -> (Ltl a, Bool)
simpl (LtlAnd Ltl a
a Ltl a
b) = Ltl a -> Ltl a -> (Ltl a, Bool)
forall a. Ltl a -> Ltl a -> (Ltl a, Bool)
simplAnd Ltl a
a Ltl a
b
simpl (LtlOr Ltl a
a Ltl a
b) = Ltl a -> Ltl a -> (Ltl a, Bool)
forall a. Ltl a -> Ltl a -> (Ltl a, Bool)
simplOr Ltl a
a Ltl a
b
simpl (LtlNext Ltl a
a) =
let (Ltl a
a', Bool
pa) = Ltl a -> (Ltl a, Bool)
forall a. Ltl a -> (Ltl a, Bool)
simpl Ltl a
a
in if Bool
pa
then (Ltl a -> Ltl a
forall a. Ltl a -> Ltl a
LtlNext Ltl a
a', Bool
True)
else (Ltl a -> Ltl a
forall a. Ltl a -> Ltl a
LtlNext Ltl a
a, Bool
False)
simpl (LtlUntil Ltl a
a Ltl a
b) = (Ltl a -> Ltl a -> Ltl a) -> Ltl a -> Ltl a -> (Ltl a, Bool)
forall a.
(Ltl a -> Ltl a -> Ltl a) -> Ltl a -> Ltl a -> (Ltl a, Bool)
recurse2 Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
LtlUntil Ltl a
a Ltl a
b
simpl (LtlRelease Ltl a
a Ltl a
b) = (Ltl a -> Ltl a -> Ltl a) -> Ltl a -> Ltl a -> (Ltl a, Bool)
forall a.
(Ltl a -> Ltl a -> Ltl a) -> Ltl a -> Ltl a -> (Ltl a, Bool)
recurse2 Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
LtlRelease Ltl a
a Ltl a
b
simpl Ltl a
x = (Ltl a
x, Bool
False)
simplAnd :: Ltl a -> Ltl a -> (Ltl a, Bool)
simplAnd :: forall a. Ltl a -> Ltl a -> (Ltl a, Bool)
simplAnd Ltl a
a Ltl a
b =
let (Ltl a
a', Bool
pa) = Ltl a -> (Ltl a, Bool)
forall a. Ltl a -> (Ltl a, Bool)
simpl Ltl a
a
(Ltl a
b', Bool
pb) = Ltl a -> (Ltl a, Bool)
forall a. Ltl a -> (Ltl a, Bool)
simpl Ltl a
b
in case (Ltl a
a', Ltl a
b') of
(Ltl a
LtlTruth, Ltl a
_) -> (Ltl a
b', Bool
True)
(Ltl a
_, Ltl a
LtlTruth) -> (Ltl a
a', Bool
True)
(Ltl a
LtlFalsity, Ltl a
_) -> (Ltl a
forall a. Ltl a
LtlFalsity, Bool
True)
(Ltl a
_, Ltl a
LtlFalsity) -> (Ltl a
forall a. Ltl a
LtlFalsity, Bool
True)
(Ltl a, Ltl a)
_ -> if Bool
pa Bool -> Bool -> Bool
|| Bool
pb then (Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
LtlAnd Ltl a
a' Ltl a
b', Bool
True) else (Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
LtlAnd Ltl a
a Ltl a
b, Bool
False)
simplOr :: Ltl a -> Ltl a -> (Ltl a, Bool)
simplOr :: forall a. Ltl a -> Ltl a -> (Ltl a, Bool)
simplOr Ltl a
a Ltl a
b =
let (Ltl a
a', Bool
pa) = Ltl a -> (Ltl a, Bool)
forall a. Ltl a -> (Ltl a, Bool)
simpl Ltl a
a
(Ltl a
b', Bool
pb) = Ltl a -> (Ltl a, Bool)
forall a. Ltl a -> (Ltl a, Bool)
simpl Ltl a
b
in case (Ltl a
a', Ltl a
b') of
(Ltl a
LtlTruth, Ltl a
_) -> (Ltl a
forall a. Ltl a
LtlTruth, Bool
True)
(Ltl a
_, Ltl a
LtlTruth) -> (Ltl a
forall a. Ltl a
LtlTruth, Bool
True)
(Ltl a
LtlFalsity, Ltl a
_) -> (Ltl a
b', Bool
True)
(Ltl a
_, Ltl a
LtlFalsity) -> (Ltl a
a', Bool
True)
(Ltl a, Ltl a)
_ -> if Bool
pa Bool -> Bool -> Bool
|| Bool
pb then (Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
LtlOr Ltl a
a' Ltl a
b', Bool
True) else (Ltl a -> Ltl a -> Ltl a
forall a. Ltl a -> Ltl a -> Ltl a
LtlOr Ltl a
a Ltl a
b, Bool
False)
recurse2 ::
(Ltl a -> Ltl a -> Ltl a) ->
Ltl a ->
Ltl a ->
(Ltl a, Bool)
recurse2 :: forall a.
(Ltl a -> Ltl a -> Ltl a) -> Ltl a -> Ltl a -> (Ltl a, Bool)
recurse2 Ltl a -> Ltl a -> Ltl a
f Ltl a
a Ltl a
b =
let (Ltl a
a', Bool
pa) = Ltl a -> (Ltl a, Bool)
forall a. Ltl a -> (Ltl a, Bool)
simpl Ltl a
a
(Ltl a
b', Bool
pb) = Ltl a -> (Ltl a, Bool)
forall a. Ltl a -> (Ltl a, Bool)
simpl Ltl a
b
in if Bool
pa Bool -> Bool -> Bool
|| Bool
pb
then (Ltl a -> Ltl a -> Ltl a
f Ltl a
a' Ltl a
b', Bool
True)
else (Ltl a -> Ltl a -> Ltl a
f Ltl a
a Ltl a
b, Bool
False)