Skip to content

Instantly share code, notes, and snippets.

@Apanatshka
Last active August 29, 2015 14:06
Show Gist options
  • Save Apanatshka/3c5880aeb3cf1d76d043 to your computer and use it in GitHub Desktop.
Save Apanatshka/3c5880aeb3cf1d76d043 to your computer and use it in GitHub Desktop.
Events vs. Signals
import Accumulatory -- whatever it is you're accumulating
sourceOfResetEvents1 : Signal a
data AccumulationCommand3 = Acc3 Accumulatory | Reset3
somethingToAccumulate1 : Signal Accumulatory.Accumulatory
zeroValue1 : Accumulatory.Accumulatory
-- The solution
accCommands3 : AccumulationCommand3
accCommands3 =
merge (always Reset3 <~ sourceOfResetEvents1)
(Acc3 <~ somethingToAccumulate1)
accumulation3 : Signal Accumulatory.Accumulatory
accumulation3 = foldp accumulate3 zeroValue1 accCommands3
accumulate3 : AccumulationCommand3
-> Accumulatory.Accumulatory
-> Accumulatory.Accumulatory
accumulate3 command oldAcc =
case command of
Reset3 -> zeroValue1
Acc3 val -> Accumulatory.add oldAcc val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment