Wiring up a basic reflex application?

262 views
Skip to first unread message

David McHealy

unread,
Mar 15, 2016, 11:17:02 AM3/15/16
to reflex-frp
I was am using reflex-dom on the frontend and quite liking it, and so I find myself on the backend working with websockets and I'd like to use plain old reflex to coordinate this stuff.  But there's no real documentation on how to wire up arbitrary IO into event triggers, all examples use reflex-dom and, and reflex-dom itself is too complicated for me to understand.

The only source I can find that has a simple example is reflex-gloss.  I'm trying to set up a simple timer event but I can't seem to get the types to be what I think they should be, or what reflex-gloss managed, so I don't think I'm using it correctly. http://hackage.haskell.org/package/reflex-gloss-0.2/docs/src/Reflex-Gloss.html#GlossApp

I should mention I'm testing with reflex on the HEAD of the develop branch.

import Control.Monad.Identity
import Data.IORef
import Data.Dependent.Sum (DSum ((:=>)))
import Control.Monad.Trans
import Control.Concurrent (threadDelay)

import Reflex
import Reflex.Class
import Reflex.Host.Class
import Reflex.Spider.Internal (SpiderHostFrame)

-- I don't know what this type should be be, but I was imaginging something like this:
-- test :: (Reflex t, MonadIO m) => (Event t () -> m ()) -> IO ()
test network = do

  runSpiderHost $ do
    (tickEvent,  tickTriggerRef)  <- newEventWithTriggerRef
    runHostFrame $ network tickEvent
    liftIO $ tick (runSpiderHost $ handleTrigger tickTriggerRef)

  where
    handleTrigger trigger = do
      mETrigger <- liftIO $ readIORef trigger
      case mETrigger of
        Nothing       -> return ()
        Just eTrigger -> fireEvents [eTrigger :=> Identity ()]
       

tick :: MonadIO m => m () -> m ()
tick f = f >> liftIO (threadDelay 2000000) >> tick f

The actual type of test is
(Reflex.Class.Event Reflex.Spider.Internal.Spider ()
         -> Reflex.Spider.Internal.SpiderHostFrame a)
              -> IO ()

which doesn't seem like what I wanted.

Sean Leather

unread,
Mar 22, 2016, 5:02:30 AM3/22/16
to refle...@googlegroups.com
Hi David,

On Tue, Mar 15, 2016 at 5:17 PM, David McHealy wrote:
I was am using reflex-dom on the frontend and quite liking it, and so I find myself on the backend working with websockets and I'd like to use plain old reflex to coordinate this stuff.  But there's no real documentation on how to wire up arbitrary IO into event triggers, all examples use reflex-dom and, and reflex-dom itself is too complicated for me to understand.

I'm afraid I don't have an answer for  you. I was hoping somebody else could help, so I posted a link to this on Reddit:


But, unfortunately, no responses there.

Perhaps you could try IRC at #reflex-frp on Freenode.

Regards,
Sean
Reply all
Reply to author
Forward
0 new messages