Skip to content

Instantly share code, notes, and snippets.

@jfischoff
Last active August 22, 2019 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfischoff/75079af9e82c27bf944f8f3352ebc075 to your computer and use it in GitHub Desktop.
Save jfischoff/75079af9e82c27bf944f8f3352ebc075 to your computer and use it in GitHub Desktop.
-- What I am struggling to do is sequence to looping things. First I have a loop where the output is feed into the
-- next step as input until it completes. Then the next loop starts.
-- I doubt this works ... I'm trying to test it now ... anyway I don't like it and feel like
-- there must be an easier way.
advance :: (Adjustable t m, MonadHold t m, Monad m, MonadFix m)
=> m (Event t (Maybe a))
-- ^ initial
-> (a -> m (Event t (Maybe a)))
-- loop step
-> (forall void. a -> m void)
-- next loop ... probably never returns
-> m ()
advance initial loopStep next = do
rec out <- networkHold initial $ ffor (updated out) $ \e -> do
rec delayed <- networkHold (delayOne e) $ ffor (switch $ current delayed) $ \case
(Just x , _) -> fmap (, Just x) <$> loopStep x
(Nothing, Just x) -> next x
(Nothing, Nothing) -> error "impossible"
pure never
pure ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment