[Haskell-cafe] Free theorem for `forall z. (A,z) -> (B,z)`?

Joachim Breitner mail at joachim-breitner.de
Tue Jul 24 19:15:26 UTC 2018


Hi,

Am Dienstag, den 24.07.2018, 14:47 -0400 schrieb Joachim Breitner:
> I guess I can use 
> https://hackage.haskell.org/package/reflex-dom-0.3/candidate/docs/Reflex-Dom-Time.html
> for this somehow. But I guess I only want to delay errors, not
> successes – I will give it a shot

Sure, why not:
https://github.com/nomeata/free-theorems-static-webui/commit/20c9aca

it seems to work. If some reflex-expert could check if this makes
sense, that would be great:

-- | Errors are delayed, but successes go through immediatelly
delayError :: (PerformEvent t m, MonadHold t m, TriggerEvent t m, MonadIO (Performable m)) =>
    Dynamic t (Either a b) -> m (Dynamic t (Either a b))
delayError d = do
    delayedEvents <- delay 0.5 (updated d)
    d' <- holdDyn Nothing (Just <$> delayedEvents)
    return $ do
        now <- d
        past <- d'
        return $ case (past, now) of
            (Nothing, _)     -> now    -- before any delayed events arrive
            (_, Right _ )    -> now  -- current value is good
            (Just x, Left _) -> x -- current value is bad, delay

Cheers,
Joachim

-- 
Joachim Breitner
  mail at joachim-breitner.de
  http://www.joachim-breitner.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180724/c9539dce/attachment.sig>


More information about the Haskell-Cafe mailing list