[Haskell-cafe] applicative question
grant
gbwey9 at gmail.com
Sun Jul 20 22:43:20 UTC 2014
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140720/b8362e07/attachment.html>
More information about the Haskell-Cafe
mailing list