]> Git — Sourcephile - tmp/julm/arpeggigon.git/blob - src/RMCA/YampaReactive.hs
Refactoring to FRP.
[tmp/julm/arpeggigon.git] / src / RMCA / YampaReactive.hs
1 {-# LANGUAGE FlexibleContexts, MultiParamTypeClasses #-}
2
3 module RMCA.YampaReactive where
4
5 import Data.ReactiveValue
6 import FRP.Yampa
7 import Hails.Yampa
8 import RMCA.IOClockworks
9
10 yampaReactiveFrom :: (ReactiveValueRead c a IO) => SF a b -> c
11 -> IO (ReactiveFieldRead IO b)
12 yampaReactiveFrom sf rv = do
13 init <- reactiveValueRead rv
14 (input,output) <- yampaReactiveDual init sf
15 rv =:> input
16 return output
17
18 yampaReactiveWithMetronome :: (ReactiveValueRead c a IO) =>
19 a -> SF a b -> c -> DTime
20 -> IO (ReactiveFieldRead IO b)
21 yampaReactiveWithMetronome init sf rv dt = do
22 clock <- mkClock dt
23 (input,output) <- yampaReactiveDual init sf
24 rv =:> input
25 reactiveValueOnCanRead clock $
26 reactiveValueRead rv >>= reactiveValueWrite input
27 return output
28
29 yampaReactiveWithTick :: (ReactiveValueRead c a IO) =>
30 a -> SF a b -> c -> IOTick
31 -> IO (ReactiveFieldRead IO b)
32 yampaReactiveWithTick init sf rv tick = do
33 (input,output) <- yampaReactiveDual init sf
34 rv =:> input
35 reactiveValueOnCanRead tick $
36 reactiveValueRead rv >>= reactiveValueWrite input
37 return output