{-# LANGUAGE FunctionalDependencies, Safe #-}
module Dep.Class.NonDeterministicWalkable (
NonDeterministicWalkable(nstep', nstep, nstepValues, nstepValues', nwalk, nwalkValues, allNstep, allNstep', allNwalk, allNstepValues, allNwalkValues)
) where
import Dep.Utils(toList')
import Control.Monad(foldM)
class NonDeterministicWalkable f step | f -> step where
nstep'
:: f a
-> step
-> [f a]
-> [f a]
nstep' f a
x step
dx = (f a -> step -> [f a]
forall (f :: * -> *) step a.
NonDeterministicWalkable f step =>
f a -> step -> [f a]
nstep f a
x step
dx [f a] -> [f a] -> [f a]
forall a. [a] -> [a] -> [a]
++)
nstep
:: f a
-> step
-> [f a]
nstep f a
x step
dx = f a -> step -> [f a] -> [f a]
forall (f :: * -> *) step a.
NonDeterministicWalkable f step =>
f a -> step -> [f a] -> [f a]
nstep' f a
x step
dx []
nstepValues' :: Foldable f
=> f a
-> step
-> [a]
-> [a]
nstepValues' f a
st step
stp = ([a] -> [f a] -> [a]) -> [f a] -> [a] -> [a]
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((f a -> [a] -> [a]) -> [a] -> [f a] -> [a]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr f a -> [a] -> [a]
forall (f :: * -> *) a. Foldable f => f a -> [a] -> [a]
toList') (f a -> step -> [f a]
forall (f :: * -> *) step a.
NonDeterministicWalkable f step =>
f a -> step -> [f a]
nstep f a
st step
stp)
nstepValues :: Foldable f
=> f a
-> step
-> [a]
nstepValues f a
st step
stp = f a -> step -> [a] -> [a]
forall (f :: * -> *) step a.
(NonDeterministicWalkable f step, Foldable f) =>
f a -> step -> [a] -> [a]
nstepValues' f a
st step
stp []
allNstep' :: Foldable g
=> g (f a)
-> step
-> [f a]
-> [f a]
allNstep' g (f a)
xs step
dx [f a]
tl = (f a -> [f a] -> [f a]) -> [f a] -> g (f a) -> [f a]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (f a -> step -> [f a] -> [f a]
forall (f :: * -> *) step a.
NonDeterministicWalkable f step =>
f a -> step -> [f a] -> [f a]
`nstep'` step
dx) [f a]
tl g (f a)
xs
allNstep :: Foldable g
=> g (f a)
-> step
-> [f a]
allNstep g (f a)
xs step
dx = g (f a) -> step -> [f a] -> [f a]
forall (f :: * -> *) step (g :: * -> *) a.
(NonDeterministicWalkable f step, Foldable g) =>
g (f a) -> step -> [f a] -> [f a]
allNstep' g (f a)
xs step
dx []
allNstepValues :: Foldable f
=> [f a]
-> step
-> [a]
allNstepValues [f a]
inis step
stps = [f a]
inis [f a] -> (f a -> [a]) -> [a]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (f a -> step -> [a]
forall (f :: * -> *) step a.
(NonDeterministicWalkable f step, Foldable f) =>
f a -> step -> [a]
`nstepValues` step
stps)
nwalk :: Foldable g
=> f a
-> g step
-> [f a]
nwalk = (f a -> step -> [f a]) -> f a -> g step -> [f a]
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM f a -> step -> [f a]
forall (f :: * -> *) step a.
NonDeterministicWalkable f step =>
f a -> step -> [f a]
nstep
nwalkValues :: (Foldable f, Foldable g)
=> f a
-> g step
-> [a]
nwalkValues f a
ini g step
stps = (f a -> [a] -> [a]) -> [a] -> [f a] -> [a]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr f a -> [a] -> [a]
forall (f :: * -> *) a. Foldable f => f a -> [a] -> [a]
toList' [] ((f a -> step -> [f a]) -> f a -> g step -> [f a]
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM f a -> step -> [f a]
forall (f :: * -> *) step a.
NonDeterministicWalkable f step =>
f a -> step -> [f a]
nstep f a
ini g step
stps)
allNwalk :: Foldable g
=> [f a]
-> g step
-> [f a]
allNwalk = (((f a -> [f a]) -> [f a])
-> (g step -> f a -> [f a]) -> g step -> [f a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f a -> g step -> [f a]) -> g step -> f a -> [f a]
forall a b c. (a -> b -> c) -> b -> a -> c
flip f a -> g step -> [f a]
forall (f :: * -> *) step (g :: * -> *) a.
(NonDeterministicWalkable f step, Foldable g) =>
f a -> g step -> [f a]
nwalk) (((f a -> [f a]) -> [f a]) -> g step -> [f a])
-> ([f a] -> (f a -> [f a]) -> [f a]) -> [f a] -> g step -> [f a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [f a] -> (f a -> [f a]) -> [f a]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
(>>=)
allNwalkValues :: (Foldable f, Foldable g)
=> [f a]
-> g step
-> [a]
allNwalkValues [f a]
inis g step
stps = [f a]
inis [f a] -> (f a -> [a]) -> [a]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (f a -> g step -> [a]
forall (f :: * -> *) step (g :: * -> *) a.
(NonDeterministicWalkable f step, Foldable f, Foldable g) =>
f a -> g step -> [a]
`nwalkValues` g step
stps)
{-# MINIMAL nstep' | nstep #-}