Skip to content

Instantly share code, notes, and snippets.

@johnpmayer
Created June 9, 2013 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnpmayer/5745402 to your computer and use it in GitHub Desktop.
Save johnpmayer/5745402 to your computer and use it in GitHub Desktop.
Using the new foldp-like loop function
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