circular dependant signal

45 views
Skip to first unread message

Jeff Smits

unread,
Feb 9, 2013, 10:42:43 AM2/9/13
to elm-d...@googlegroups.com
Hey guys,

I've got a question for you. Can I create a circular dependent signal? Or do you know another way to solve the following problem.

My game is supposed to run at a certain FPS. But when paused I want the CPU to take a break. Obviously, I'll use fpsWhen. I have that right now and is works on this boolean signal I have called playing, which changes its value when spacebar is pressed. 
So far so good. But now I want the game logic to be able to pause the game as well... All this seems impossible without ditching the fpsWhen. Because fpsWhen need playing and is then used to more userinput, this userinput is given to the lifted stepGame along with a state signal, which can find out if the game want itself to pause. So stepGame can output a (pause, newState):(Bool, State) but then I have to merge the first part with playing again...

Evan Czaplicki

unread,
Feb 9, 2013, 1:34:13 PM2/9/13
to elm-d...@googlegroups.com
It is possible but difficult, and I have been thinking of a nicer way to do it.

Right now you can use the FFI to export a signal and then import it again directly. This will create a loop.

I'd like to bring this functionality into the language itself with some primitive in the Signal library, but I have not come up with a nice way to do it. I was thinking something like (loop :: a -> Signal a -> Signal a) but you wouldn't be able to actually use it recursively. Perhaps a top-level declaration would be the best way to do it, but I am unsure on syntax for that.

If you create a cycle, it is easy to create an infinite loop, so you'd have to be careful to filter the exported signal to only trigger when it is absolutely necessary. One feature of Elm is that it is impossible to create cycles within the system itself. This is very important for creating programs that terminate, but makes things harder in this case. The ideas above would all introduce an external cycle.


--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages