newBehavior :: a -> Interval (Behavior a, a -> IO ())
newBehavior initial = do
    value <- liftIO $ newIORef initial
    ll    <- liftIO $ atomically LinkedList.empty
    let b = Behavior
            { sample = readIORef value
            , listen = \k -> do
                node <- liftIO . atomically $ LinkedList.insert k ll
                finally . atomically $ LinkedList.delete node
            , cached = True
            }
        update !a = do
            writeIORef value a
            hs <- atomically $ LinkedList.toList ll
            mapM_ ($ a) hs
    defer . finally . atomically $ LinkedList.clear ll
    return (b, update)
newBehavior :: a -> Interval (Behavior a, a -> IO ())
newBehavior initial = do
    value <- liftIO $ newIORef initial
    ll    <- liftIO $ atomically LinkedList.empty
    let b = Behavior
            { sample = readIORef value
            , listen = \k -> do
                node <- liftIO . atomically $ LinkedList.insert k ll
                finally . atomically $ LinkedList.delete node
            , cached = True
            }
        update !a = do
            writeIORef value a
            hs <- atomically $ LinkedList.toList ll
            mapM_ ($ a) hs
    defer . finally . atomically $ LinkedList.clear ll
    return (b, update)
newBehavior initial = do
    value <- liftIO $ newIORef initial
    ll    <- liftIO $ atomically LinkedList.empty
    let b = Behavior
            { sample = readIORef value
            , listen = \k -> do
                node <- liftIO . atomically $ LinkedList.insert k ll
                finally . atomically $ LinkedList.delete node
            , cached = True
            }
        update !a = do
            writeIORef value a
            hs <- atomically $ LinkedList.toList ll
            mapM_ ($ a) hs
    defer . finally . atomically $ LinkedList.clear ll
    return (b, update)