Fix StateT and ReaderT interleave instances

This commit is contained in:
Danila Fedorin 2023-03-11 23:35:55 -08:00
parent 95c83a1ec0
commit 398fccecf0

View File

@ -31,11 +31,11 @@ instance MonadLogic m => MonadLogic (StateT s m) where
case r of
Nothing -> pure (Nothing /\ s)
Just ((a /\ s') /\ m) -> pure (Just (a /\ (StateT $ const m)) /\ s')
interleave m1 m2 = StateT $ \s -> runStateT m1 s <|> runStateT m2 s
interleave m1 m2 = StateT $ \s -> runStateT m1 s `interleave` runStateT m2 s
instance MonadLogic m => MonadLogic (ReaderT r m) where
msplit sm = ReaderT $ \r -> do
msplit (runReaderT sm r) >>= case _ of
Nothing -> pure Nothing
Just (a /\ m) -> pure $ Just $ a /\ (ReaderT $ const m)
interleave m1 m2 = ReaderT $ \r -> runReaderT m1 r <|> runReaderT m2 r
interleave m1 m2 = ReaderT $ \r -> runReaderT m1 r `interleave` runReaderT m2 r