
Hi guys, I am trying to simplify some code. A user provides a combination of boolean expressions and for each expression an async task is run until that expression becomes true. The boolean expressions have type (Event e => e -> Bool) eg (PC.availableFlag .&&. "asmith" .== PC.userId) Unfortunately the way I have coded this, the user needs to include the \r -> r ? for each expression, with a unique number indicating the position in the sequence (so I can keep track of the asyncs when restarting after a failure). The 'r' function just wraps the expression in a Concurrently constructor. r :: (forall e.Event e => (e -> Bool) -> Concurrently e) -> Concurrently a Here is a sample expression that someone might provide: expr1 = runit (\r -> (,) <$> r 1 (PC.availableFlag .&&. "asmith" .== PC.userId) <*> r 2 (22 .== SC.signalNumber)) So, is there a way to rewrite or simplify this to avoid having to pass the r + unique Int to each subexpression? Or, is there a different format that I can write this in and then transform to the Concurrently applicative? Here is the runit method: runit expr = runConcurrently (expr (Concurrently . queryToIOAction)) And some more sample queries: expr1 = runit (\r -> r (PC.availableFlag .&&. "asmith" .== PC.userId)) expr2 = runit (\r -> (,) <$> r 1 (PC.availableFlag .&&. "asmith" .== PC.userId) <*> r 2 (22 .== SC.signalNumber)) expr3 = runit (\r -> (\(a b -> Left (a,b)) <$> r 1 (PC.availableFlag .&&. "asmith" .== PC.userId) -- (Event e => e -> Bool) <*> r 2 (2 .== SC.signalNumber)) <|> Right <$> r 3 (1 .== SC.signalNumber)) Thanks for any help! Grant
participants (1)
-
grant