Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traversing or binding over a bot? #87

Open
solomon-b opened this issue Jan 14, 2024 · 0 comments
Open

Traversing or binding over a bot? #87

solomon-b opened this issue Jan 14, 2024 · 0 comments

Comments

@solomon-b
Copy link
Member

I often find myself looking at operations like:

(/.\) :: Monad m => Bot m s i o -> Bot m s' i o -> Bot m (s /\ s') i o
(/.\) (Bot b1) (Bot b2) = Bot $ \(s1, s2) i -> do
  Functor.combine (b1 s1 i, b2 s2 i) >>= \case
    This (o, s1') -> pure (o, (s1', s2))
    That (o', s2') -> pure (o', (s1, s2'))
    These (o, s1') (o', s2') -> toListT [(o, (s1', s2)), (o', (s1', s2'))]

And think that I can replace this with a dimap on a particular Semigroupal instance. In this case it almost works to use Trifunctor.combine @_ @_ @These @These:

(/.\) :: Monad m => Bot m s i o -> Bot m s' i o -> Bot m (s /\ s') i o
(/.\) b1 b2 = dimap (\i -> These i i) _ $ Trifunctor.combine @_ @_ @These @These (b1, b2)

However you end up needing to do something impossible in the rmap side. In this case we need These o o -> o which means discarding an output. The original implementation gets around this because we are binding over the ListT inside the bot.

This exact situation arises often and I'm wondering if there is some other combinator we could leverage or more likely implement that is more powerful then rmap. Maybe some kind of traverse or bind?

We need to be be able to bind over the bot and work with the inner ListT structure (or perhaps even the m inside the ListT?)

@masaeedu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant