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

bearriver: add dpSwitch #331

Closed
geroldmeisinger opened this issue Sep 6, 2022 · 3 comments
Closed

bearriver: add dpSwitch #331

geroldmeisinger opened this issue Sep 6, 2022 · 3 comments

Comments

@geroldmeisinger
Copy link
Contributor

geroldmeisinger commented Sep 6, 2022

BearRiver is missing some definitions available in Yampa. One such definition is dpSwitch.

an implementation of dpSwitch has been provided by Jonathan Thaler at #40 (comment):

dpSwitch :: (Monad m, Traversable col)
         => (forall sf. (a -> col sf -> col (b, sf)))
         -> col (SF m b c) 
         -> SF m (a, col c) (Event d) 
         -> (col (SF m b c) -> d -> SF m a (col c))
         -> SF m a (col c)
dpSwitch rf sfs sfF sfCs = MSF $ \a -> do
  let bsfs = rf a sfs
  res <- T.mapM (\(b, sf) -> unMSF sf b) bsfs
  let cs   = fmap fst res
      sfs' = fmap snd res
  (e,sfF') <- unMSF sfF (a, cs)
  let ct = case e of
          Event d -> sfCs sfs' d
          NoEvent -> dpSwitch rf sfs' sfF' sfCs
  return (cs, ct)

EDIT: Ivan Perez: Added a short description and brought in text from different issue to help process this independently without jumping around.

geroldmeisinger added a commit to geroldmeisinger/dunai that referenced this issue Sep 6, 2022
Parallel composition and switching over collections with routing
Implementation by thalerjonathan (see issue ivanperez-keera#40).

copied code doc from Yampa
geroldmeisinger added a commit to geroldmeisinger/dunai that referenced this issue Sep 6, 2022
@ivanperez-keera
Copy link
Owner

ivanperez-keera commented Sep 6, 2022

Some steps required to determine if we can add this implementation are:

  • Is it extensionally the same as the one in Yampa? One can test them by hand, but 9285e4e offers a systematic way of checking that an implementation in Bearriver and one in Yampa behave the same way.
  • Does it leak? For that it would be good to run it with a long trace and see that performance does not degrade. You can use the same approach as in step (1) to generate very long traces, but make sure you whnf the outputs.
  • Could it be simplified? In particular, is there a way to write it using existing combinators without making the code harder to understand?
  • Is the code understandable? From re-writing to renaming variables to adding comments; if it's not very obvious to you how it works, it won't be understandable to others. Avoid repetition of work by helping others understand it. (Hint: it isn't)
  • Is it conformant with our style guide? See https://github.com/ivanperez-keera/dunai#style for details. (Hint: it isn't)

@ivanperez-keera
Copy link
Owner

For context: I've been adding missing definitions as subissues of #40. If you look at the recent history of that issue, you'll see that several modules from Yampa have been added to BearRiver. The module Switches now exists, but it's incomplete. The proposed dpSwitch would fit in that module, but it'll take me some time to get there: I'm trying to go in order so that I don't miss things.

@ivanperez-keera
Copy link
Owner

ivanperez-keera commented Jun 24, 2024

Closed in favor of #426 .

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

No branches or pull requests

2 participants