reactive-banana

Implementing a timer in Traveller game

廉价感情. 提交于 2019-12-22 18:04:29
问题 This problem is a continuation of what I started here. I'm using the asteroid example as a model to work from. The problem I want to talk about here is the one of a timer. The asteroids example uses the event0 function to make one, which relies on the Graphics.UI.WX library. I don't want to use WX for this project. Could someone tell me what event0 is doing generally, so that I can figure out what I need to do to make a similar function? 回答1: To bind reactive-banana to an external event-based

Reactive Banana: how to use values from a remote API and merge them in the event stream

心不动则不痛 提交于 2019-12-21 17:22:33
问题 I am using Reactive-Banana in a WX interface. I need to retrieve a value from an external service API when a button is pressed. I have a generic Behavior based on the data type AppState that “accums” the transformed changes based on a function transformation ( doSomeTransformation ). The values that get transformed are transported by the events and they come from a remote API ( getRemoteValue ) when a button on the interface is pressed. I have written a slim version of the code that

reactive-banana: How to create an AddHandler?

こ雲淡風輕ζ 提交于 2019-12-21 07:29:37
问题 I'm currently trying to get to know FRP through Heinrich Apfelmus' reactive-banana, which seems to be a quite well documented and simple library, compared to the other ones I've looked at. However, I can't wrap my head around the AddHandler type. Let's say I want to use GLFW to get mouse button clicks so that I have something like eMouseButton :: Event () . Looking at the examples, it seems that I'd somehow have to use fromAddHandler, but I have no idea how to assemble that AddHandler

Does push-pull FRP help when implementing games?

孤街醉人 提交于 2019-12-20 09:30:19
问题 I've been comparing pull-only FRP (ie netwire) with push-pull FRP (ie reactive-bannana) in the implementation of games. Are there advantages to one over the other? Things I've notices are: Push events make it easy to have events for mouse clicks / key presses from GLFW or GLUT Arrowized FRP that netwire uses has much less IO floating around, which is always better. It looks like having pull-only responses to things like mouse movement could cause time leaks. What else have I missed? Edit, to

“Behavior now” in FRP

馋奶兔 提交于 2019-12-19 05:45:17
问题 In a previous SO question (Is it possible?: Behavior t [Behavior t a] -> Behavior t [a]) we were analyzing the existence of a Behavior join (to use reactive-banana terms). Behavior t (Behavior t a) -> Behavior t a Implemented in the semantic model as follows type Behavior t a = t -> a behaviorNow :: Behavior t (Behavior t a) -> Behavior t a behaviorNow f t = f t t While implementing this directly would be unfortunate since we could produce a Behavior Monad using const and behaviorNow , if and

Functional-Banana Traveller Game - Intriguing and Maddening

倖福魔咒の 提交于 2019-12-18 12:23:24
问题 I want to use reactive-banana to write a traveller game that people can write bots for. FRP is completely new to me, and I'm having trouble making a start. I created a more elaborate Graph, when I began, but for my purposes here, I have tried to make it as simple as possible. I'd like some guidance, mostly on where to begin, and how to break this bigger problem down into smaller problems to solve. Here's the initial design. The idea is to have a Graph of LNodes (with weighted edges I am

Functional Banana Traveller - putting together Behavior t GameState

被刻印的时光 ゝ 提交于 2019-12-12 18:11:47
问题 The problem is that I do not know how to create the Behavior of type Behavior t GameState I have more code, but am trying to just show what I think is neccessary to talk about the problem. Let me know if there are blanks to be filled in. Here's what I have : data GameState = GameState {agent :: Agent ,universe :: Universe } type Universe = Gr Planet () data Command = Move PlanetName | Look | Quit deriving Show data PlayerCommand = PlayerCommand Command PID | Null deriving Show updateGS ::

Dynamic event switching in reactive-banana causes severe leak

巧了我就是萌 提交于 2019-12-12 12:26:40
问题 I'm not sure whether this behavior is expected (i.e. I'm misusing Reactive.Banana.Switch) or a bug. Let's say I have two like-typed input Behaviors, and I want to switch between them based on an Event. I wrote this function: switchBehaviors :: Behavior t a -- | Behavior to yield initially and after "True" events -> Behavior t a -- | Behavior to yield after "False" events -> Event t Bool -- | Select between behaviors -> Moment t (Behavior t a) switchBehaviors t f es = do t' <- trimB t f' <-

Separating State for a Model and GUI IO ( Wx) : Stack or FRP?

折月煮酒 提交于 2019-12-11 00:35:04
问题 For my diagramming tool, I'd like to keep the code of the core model isolated from the GUI. In the following example, the "state " is passed around with vDiag , which is a Tvar . This is a design decision in wx. Now, For my diagramming tool, I 'd like the core model to be "stored" in a fgl Graph, (with complex types in it), and wx will be given only a view on it; say in this example, a list of points for read access when painting, and some functions to write when clicking, dragging, etc.. . I

Is it possible?: Behavior t [Behavior t a] -> Behavior t [a]

随声附和 提交于 2019-12-10 19:03:50
问题 Is there a way to have a Behavior t [a] where the values of [a] at time t are the values contained in a Behavior t [Behavior t a] at time t? I.e, a function with the type of: Behavior t [Behavior t a] -> Behavior t [a] If this is not possible, is that because of a logical impossibility or a limitation in reactive-banana? 回答1: The type is trivially inhabited for any Applicative : {-# LANGUAGE RankNTypes #-} import Control.Applicative import Control.Monad import Data.Functor.Identity import