2023-02-27 20:32:51 -08:00
|
|
|
module Test.Main where
|
|
|
|
|
|
|
|
import Prelude
|
|
|
|
|
2023-02-28 18:54:24 -08:00
|
|
|
import Control.Alternative (guard, (<|>))
|
|
|
|
import Control.Monad.Logic.Class (class MonadLogic, interleave)
|
2023-03-04 19:01:57 -08:00
|
|
|
import Control.Monad.Logic.Trans (runSFKT)
|
2023-02-28 18:54:24 -08:00
|
|
|
import Control.Monad.Reader.Class (class MonadReader)
|
|
|
|
import Control.Monad.Reader.Trans (runReaderT, ask)
|
|
|
|
import Control.Monad.State.Class (class MonadState)
|
|
|
|
import Control.Monad.State.Trans (runStateT, put, get)
|
|
|
|
import Data.Maybe (Maybe)
|
|
|
|
import Data.Tuple (fst)
|
|
|
|
import Data.Tuple.Nested(type (/\), (/\))
|
2023-02-27 20:32:51 -08:00
|
|
|
|
2023-02-28 18:54:24 -08:00
|
|
|
test :: forall m. MonadState String m => MonadReader Int m => MonadLogic m => m (Int /\ String)
|
|
|
|
test =
|
|
|
|
do
|
|
|
|
(yield 1 <|> yield 2) `interleave` (yield 3 <|> yield 4)
|
|
|
|
where
|
|
|
|
yield n = do
|
|
|
|
offset <- ask
|
|
|
|
oldState <- get
|
|
|
|
put (show n)
|
|
|
|
newState <- get
|
|
|
|
pure ((offset+n) /\ (oldState <> " became " <> newState))
|
|
|
|
|
|
|
|
order1 :: Maybe String
|
2023-03-04 19:01:57 -08:00
|
|
|
order1 = show <$> (runReaderT (runSFKT (fst <$> runStateT (test >>= \(x /\ s) -> guard (x `mod` 2 == 1) >>= \_ -> pure (x /\ s)) "initial")) 11)
|
2023-02-28 18:54:24 -08:00
|
|
|
|
|
|
|
order2 :: Maybe String
|
2023-03-04 19:01:57 -08:00
|
|
|
order2 = show <$> fst <$> (runStateT (runReaderT (runSFKT (test >>= \(x /\ s) -> guard (x `mod` 2 == 1) >>= \_ -> pure (x /\ s))) 11) "initial")
|
2023-02-28 18:54:24 -08:00
|
|
|
|
|
|
|
order3 :: Maybe String
|
2023-03-04 19:01:57 -08:00
|
|
|
order3 = show <$> fst <$> (runStateT (runReaderT (runSFKT test) 0) "initial")
|
2023-02-28 18:54:24 -08:00
|
|
|
|
|
|
|
main :: Maybe String
|
|
|
|
main = order1
|