Creating a Behavior for a continuously measurable phenomenon : <p>I would like to create a <code>Behavior t a</code> from an <code>IO a</code>, with the intended semantics that the IO action would be run every time the behavior is <code>sample</code>d:</p>

<pre><code>{- language FlexibleContexts #-}
import Reflex.Dom
import Control.Monad.Trans

onDemand :: (MonadWidget t m, MonadIO (PullM t)) =&gt; IO a -&gt; m (Behavior t a)
</code></pre>

<p>I hoped I could do this by just executing the <code>measurement</code> in a <code>pull</code>:</p>

<pre><code>onDemand measure = return $ pull (liftIO measure)
</code></pre>

<p>However, the resulting <code>Behavior</code> never changes after an initial <code>measure</code>ment.</p>

<p>The workaround I could come up with was to create a dummy <code>Behavior</code> that changes "frequently enough" and then create a fake dependency on that:</p>

<pre><code>import Data.Time.Clock as Time

hold_ :: (MonadHold t m, Reflex t) =&gt; Event t a -&gt; m (Behavior t ())
hold_ = hold () . (() &lt;$)

onDemand :: (MonadWidget t m, MonadIO (PullM t)) =&gt; IO a -&gt; m (Behavior t a)
onDemand measure = do
    now &lt;- liftIO Time.getCurrentTime
    tick &lt;- hold_ =&lt;&lt; tickLossy (1/1200) now
    return $ pull $ do
        _ &lt;- sample tick
        liftIO measure
</code></pre>

<p>This then works as expected; but since <code>Behavior</code>s can only be sampled on demand anyway, this shouldn't be necessary. </p>

<p>What is the correct way to create a <code>Behavior</code> for a continuous, observable-at-any-time phenomenon?</p>
