[Haskell-cafe] Instances for continuation-based FRP
Hans Höglund
hans at hanshoglund.se
Tue Apr 23 15:22:37 CEST 2013
Hi everyone,
I am experimenting with various implementation styles for classical FRP. My current thoughts are on a continuation-style push implementation, which can be summarized as follows.
> newtype EventT m r a = E { runE :: (a -> m r) -> m r -> m r }
> newtype ReactiveT m r a = R { runR :: (m a -> m r) -> m r }
> type Event = EventT IO ()
> type Reactive = ReactiveT IO ()
The idea is that events allow subscription of handlers, which are automatically unsubscribed after the continuation has finished, while reactives allow observation of a shared state until the continuation has finished.
I managed to write the following Applicative instance
> instance Applicative (ReactiveT m r) where
> pure a = R $ \k -> k (pure a)
> R f <*> R a = R $ \k -> f (\f' -> a (\a' -> k $ f' <*> a'))
But I am stuck on finding a suitable Monad instance. I notice the similarity between my types and the ContT monad and have a feeling this similarity could be used to clean up my instance code, but am not sure how to proceed. Does anyone have an idea, or a pointer to suitable literature.
Best regards,
Hans
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130423/ca47890a/attachment.htm>
More information about the Haskell-Cafe
mailing list