turion / rhine

Haskell Functional Reactive Programming framework with type-level clocks
http://hackage.haskell.org/package/rhine
117 stars 21 forks source link

Add Never clock #297

Closed ners closed 3 months ago

ners commented 3 months ago

As seen in: https://github.com/ners/rhine-linux/blob/master/kitchen-sink/Main.hs

Some clocks may fail to initialise (e.g. because they depend on missing external resources), but we would like to recover gracefully by replacing them with a clock that never ticks.

And so we introduce a clock that never ticks, but can produce anything:

initFallibleClock
    :: forall m cl
     . ( Clock m cl
       , MonadIO m
       , MonadCatch m
       , Time cl ~ Time Never
       )
    => cl
    -> RunningClockInit m (Time cl) (Tag cl)
initFallibleClock cl = catchAll (initClock cl) $ const $ initClock Never <&> first (>>^ second absurd)
turion commented 3 months ago

Thanks a lot! This is a useful addition.

This clock does not actually run in MonadIO because it is modelled after FRP.Rhine.Clock.Realtime.Busy, which runs in IO. We should probably make both of them MonadIO in the future.

I agree, we should, and indeed I think Never can already be in MonadIO. Busy can be changed later.

turion commented 3 months ago

Have you seen https://github.com/turion/rhine/pull/287? I think this will interplay really nicely with Never!