turion / essence-of-live-coding

Universal Live Coding & Functional Reactive Programming Framework
https://www.manuelbaerenz.de/#computerscience
64 stars 6 forks source link

Add foreverCE #89

Open turion opened 2 years ago

turion commented 2 years ago
miguel-negrao commented 2 years ago

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.

turion commented 2 years ago

Yes, I should add that function.