basically i am dealing with a 3rd party library, (interactive brokers tws api), that takes an interface with lots of different methods that it calls when an event occurs. like received market data, received order, etc... It provides another interface that basically generates these events.
Some of the events are statefull, like i canceled an order, i get a response that the order cancel was received, and then i get a confirmation that the order was canceled. If i was implementing this in haskell, (i am at the moment, but writing the bindings is a pain in the arse), i would pump all the events into a Chan, essentially a lazy evaluated sequence used to get stuff from IO, and write a parser on top of that. The most popular parser in haskell is http://legacy.cs.uu.nl/daan/download/parsec/parsec.html, which is generalized to arbitrary tokens. What i want my parser to do is to capture the cancel request protocol without me keeping track of state variables, and parsers are really good at that. data CancelResult = OrderCanceled | OrderNotCanceled cancelOrder = do { pendingCancel --succedes if a pending cancel event was parsed ; { do orderCanceled --succeeds if a successfull order cancel event was parsed ; return OrderCanceled --returns a new token reprsetning that the event was successfully canceled } <|> { orderNotCanceled ; return OrderNotCanceled } } given taht a parser to recognize that an order is pending, cancelend and notcancelled exists, i can write a parser that captures the state and returns whether one has been canceled or not. I've basically compressed the context sensitive events into something much simpler. I can write parsers on top of the data types that my previous parser generates, essentailly compressing state information from one pass to the other. Anatoly On Wed, Mar 11, 2009 at 4:35 PM, CuppoJava <patrickli_2...@hotmail.com> wrote: > > Hi Anatoly, > Unfortunately I don't know of a nice way of expressing an event-driven > architecture in Clojure, but I'm very interested in what you said > about accomplishing it in Haskell. > > Would you mind explaining that in some more detail? Perhaps if I > understood it, I can even help come up with a Clojure equivalent. > > Thanks very much > -Patrick > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---