<div dir="ltr"><div class="gmail_quote"><br><div dir="ltr"><div><div>Yes it looks like, but I don't think it is: the argument function in ListEvent is taking a list itself, so that's not a fold.<br></div>It's a sort of interruptible computation (since as soon as the argument function returns Just, we remove all remaining events).<br>

</div>But I'm sure there is a better way to write it. <br><br><div><div><div class="gmail_extra"><div class=""><font face="'Helvetica Neue', 'Helvetica Neue', Helvetica, Arial, sans-serif"><span style="font-size:14px;font-family:'Helvetica Neue','Helvetica Neue',Helvetica,Arial,sans-serif"><span style="font-family:courier new,monospace">ListEvent  :: [Event a] -> ([a] -> Maybe b) -> Event b </span>
</span></font><br><br></div><div><div class="h5"><div class="gmail_quote"><br>On Fri, Jun 20, 2014 at 4:31 PM, Kyle Marek-Spartz <span dir="ltr"><<a href="mailto:kyle.marek.spartz@gmail.com" target="_blank">kyle.marek.spartz@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="'Helvetica Neue', 'Helvetica Neue', Helvetica, Arial, sans-serif"><span style="font-size:14px;font-family:'Helvetica Neue','Helvetica Neue',Helvetica,Arial,sans-serif">Isn’t this a fold?<br>

<br>–<div>Kyle Marek-Spartz</div><div><br><br><br>On Jun 20, 2014, 7:59:41 AM, Corentin Dupont <<a href="mailto:corentin.dupont@gmail.com" target="_blank">corentin.dupont@gmail.com</a>> wrote:<hr><div><div>
 <div dir="ltr"> <div> <div>Nobody on that?<br></div> What I really want is: a computation that can be interrupted if enough result is already there.<br></div> I would be surprise if that concept doesn't exist already somewhere :)<br>

</div> <div class="gmail_extra"> </div><br><br><div class="gmail_quote">On Thu, Jun 19, 2014 at 5:17 PM, Corentin Dupont <span dir="ltr"><<a href="mailto:corentin.dupont@gmail.com" target="_blank">corentin.dupont@gmail.com</a>></span> wrote:
<br> <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div dir="ltr"> <div> <div>Hi guys,
<br>
</div> <div>I am making a DSL for event composition (inspired from digestive-functor & reactive-banana) and I find myself wanting a primitive like that:
<br> <span style="font-family:courier new,monospace">
<br> -- given a list of events, evaluate the function on those that have already fired.
<br> -- returns an event yelding the result when ready.
<br> ListEvent  :: [Event a] -> ([a] -> Maybe b) -> Event b </span>
<br>  
<br>
</div> Does this type tell you something? Is there a better abstraction that can encompass it?
<br>
</div> <div>My DSL is like that:
<br>  
<br>
</div> <div> <div><span style="font-family:courier new,monospace">-- | Composable events
<br> data Event a where
<br>    SumEvent   :: Event a -> Event a -> Event a        -- The first event to fire will be returned
<br>    AppEvent   :: Event (a -> b) -> Event a -> Event b -- Both events should fire, and then the result is returned
<br>    PureEvent  :: a -> Event a                         -- Create a fake event. The result is useable with no delay.
<br>    EmptyEvent :: Event a                              -- An event that is never fired.
<br>    BaseEvent  :: (Typeable a) => Field a -> Event a   -- Embed a base event</span>
<br>  
<br>
</div> <div>It's easy to define instances for Applicative and Alternative.
<br>
</div> <div>But then I have a use case that I cannot solve:
<br>
</div> <div>In the case of votations (which use this DSL), sometime you can end prematuraly the voting, even if not everybody voted yet: for example if the majority is already reached.
<br>
</div> <div>In this case no need to wait for everybody, we can end the vote.
<br>
</div> <div>
<br> This does not seem to be possible with Applicative or Monad interfaces: things have to be sequenced in a monad, they cannot be evaluated in parralel.
<br>
</div> <div>For example:
<br> <span style="font-family:courier new,monospace">
<br></span>
</div> <div><span style="font-family:courier new,monospace">do
<br></span>
</div> <div><span style="font-family:courier new,monospace">   v1 <- getVote1
<br></span>
</div> <div><span style="font-family:courier new,monospace">   v2 <- getVote2
<br></span>
</div> <div><span style="font-family:courier new,monospace">   v3 <- getVote3
<br></span>
</div> <div><span style="font-family:courier new,monospace">   evalMajority(v1, v2, v3)</span>
<br>  
<br>
</div> <div>In this example I have to wait for all 3 votes to be completed, but in fact only two would suffice to achieve majority.
<br>
</div> <div>That's why I added "ListEvent" to the DSL above which allow to achieve that but I'm wondering if there is a better/bigger abstraction to put it in.
<br>  
<br>
</div> <div>Thanks!!<span><font color="#888888">
<br></font></span>
</div> <div><span><font color="#888888">Corentin
<br></font></span>
</div> <div><span><font color="#888888">
<br></font></span>
</div>  
</div>  
</div> </blockquote>  
</div>  
<br></div></div>
   _______________________________________________  
<br>Haskell-Cafe mailing list  
<br><a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a>  
<br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a>  
<br> <br><br></div></span></font></blockquote></div><br></div></div></div></div></div></div>
</div><br></div>