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

Add foreverCE #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add foreverCE #89

wants to merge 1 commit into from

Conversation

turion
Copy link
Owner

@turion turion commented Dec 30, 2021

  • Haddock
  • Small unit test
  • Rethink naming
  • Is there a more general function, maybe like withCell :: (Cell m a b -> Cell n c d) -> CellExcept a b m e -> CellExcept c d n e?

@miguel-negrao
Copy link
Contributor

I find the following function useful also. foreverE requires use of the Reader monad, which requires lifting cells with a specific monad into the Reader layer. Often there is no need to send the exception value deep into the cell hierarchy via Reader, and using the exception value as extra input is cleaner (less use of liftCell).

foreverE' ::
    (Monad m, Data e) =>
    e -> Cell (ExceptT e m) (e,a) b -> Cell m a b
foreverE' e cell = foreverE e (readerToInput cell) where
    readerToInput cell = proc a -> do
        e <- constM ask -< ()
        liftCell cell -< (e,a)

My big breakthrough in understanding foreverE was when I understood that, actually, there is no Finite requirement on the exception type as long as we don't try to use exception to determine the "shape" of the cell, and just use it as an input to the cell. I suspect many recursive switching definitions are of this type. Together with resampleListPar which dynamically creates n cells based on input list size, this already allows to cover situations where the the switching changes the number of cells but not the general "shape" of the cells. Still, a continuation based approach without the Finite requirement would obviously be more powerful.

foreverCE e f = foreverE e $ commute $ runCellExcept . f

foreverCE' ::
(Monad m, Data void, Finite void, Data e, Finite e) =>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could avert the constraints on void by plugging in Void instead. Weird it's necessary at all. Have a look again whether I can get rid of them, and write a test just to see whether they are a nuisance.

@turion
Copy link
Owner Author

turion commented Feb 26, 2022

Yes, I should add that function.

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

Successfully merging this pull request may close these issues.

2 participants