FRPNow icon indicating copy to clipboard operation
FRPNow copied to clipboard

futuristic can break whenJust

Open tylerwx51 opened this issue 10 years ago • 0 comments

I just found an issue with emptyEs, more specifically with futuristic and how it interacts with the never event. After some trials and profiling this was the simplest program to cause the issue. The broken function just does nothing, it just waits forever. The working function prints "test" after e1 has fired.

import Control.FRPNow

broken :: IO ()
broken = runNowMaster $ do
    (e1, trigger1) <- callback
    sync $ trigger1 ()

    e2 <- sample $ futuristic $ return never
    e3 <- sample $ whenJust $ return Nothing `switch` fmap (pure . Just) e1 `switch` fmap (pure . Just) e2

    plan $ (sync $ print "test") <$ e3
    return never

working :: IO ()
working = runNowMaster $ do
    (e1, trigger1) <- callback
    sync $ trigger1 ()

    e2 <- sample $ return $ never
    e3 <- sample $ whenJust $ return Nothing `switch` fmap (pure . Just) e1 `switch` fmap (pure . Just) e2

    plan $ (sync $ print "test") <$ e3
    return never

The only difference in this code is in how e2 is produced, the broken one uses futuristic. This could cause programs to hang when emptyEs is used, particular when used with Control.FRPNow.Lib.first.

I'm currently using Compiler: GHC 7.10.2 OS : Mac OS X 10.11

tylerwx51 avatar Feb 08 '16 22:02 tylerwx51