Created
June 9, 2013 21:50
-
-
Save johnpmayer/5745402 to your computer and use it in GitHub Desktop.
Using the new foldp-like loop function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Loop where | |
import Graphics.Input (checkbox) | |
-- compiler note, impossible to put a valid type signature here | |
-- check : Signal Element | |
-- power : Signal Bool | |
(check, power) = checkbox true | |
tick : Signal Time | |
tick = fpsWhen 1 power | |
update : Time -> Int -> Int | |
update _ n = n + 1 | |
-- loop : (Signal a -> Signal b -> Signal b) -> b -> Signal a -> Signal b | |
-- loop transform after initial | |
count : Signal Int | |
count = loop (lift2 update) 0 tick | |
-- Display | |
main : Signal Element | |
main = (\ses -> flow down <~ combine ses) $ | |
[ check | |
, asText <~ count | |
] | |
-- Just for fun | |
myFoldp f init input = loop (\previous -> f <~ input ~ previous) init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment