[Haskell-cafe] Fwd: Do you recognize this type?

Corentin Dupont corentin.dupont at gmail.com
Fri Jun 20 15:09:30 UTC 2014


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.
It's a sort of interruptible computation (since as soon as the argument
function returns Just, we remove all remaining events).
But I'm sure there is a better way to write it.

ListEvent  :: [Event a] -> ([a] -> Maybe b) -> Event b


On Fri, Jun 20, 2014 at 4:31 PM, Kyle Marek-Spartz <
kyle.marek.spartz at gmail.com> wrote:

> Isn’t this a fold?
>
>> Kyle Marek-Spartz
>
>
>
> On Jun 20, 2014, 7:59:41 AM, Corentin Dupont <corentin.dupont at gmail.com>
> wrote:
> ------------------------------
>  Nobody on that?
> What I really want is: a computation that can be interrupted if enough
> result is already there.
> I would be surprise if that concept doesn't exist already somewhere :)
>
>
> On Thu, Jun 19, 2014 at 5:17 PM, Corentin Dupont <
> corentin.dupont at gmail.com> wrote:
>
>>  Hi guys,
>>  I am making a DSL for event composition (inspired from
>> digestive-functor & reactive-banana) and I find myself wanting a primitive
>> like that:
>>
>> -- given a list of events, evaluate the function on those that have
>> already fired.
>> -- returns an event yelding the result when ready.
>> ListEvent  :: [Event a] -> ([a] -> Maybe b) -> Event b
>>
>>  Does this type tell you something? Is there a better abstraction that
>> can encompass it?
>>  My DSL is like that:
>>
>>  -- | Composable events
>> data Event a where
>>    SumEvent   :: Event a -> Event a -> Event a        -- The first event
>> to fire will be returned
>>    AppEvent   :: Event (a -> b) -> Event a -> Event b -- Both events
>> should fire, and then the result is returned
>>    PureEvent  :: a -> Event a                         -- Create a fake
>> event. The result is useable with no delay.
>>    EmptyEvent :: Event a                              -- An event that is
>> never fired.
>>    BaseEvent  :: (Typeable a) => Field a -> Event a   -- Embed a base
>> event
>>
>>  It's easy to define instances for Applicative and Alternative.
>>  But then I have a use case that I cannot solve:
>>  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.
>>  In this case no need to wait for everybody, we can end the vote.
>>
>> 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.
>>  For example:
>>
>>  do
>>     v1 <- getVote1
>>     v2 <- getVote2
>>     v3 <- getVote3
>>     evalMajority(v1, v2, v3)
>>
>>  In this example I have to wait for all 3 votes to be completed, but in
>> fact only two would suffice to achieve majority.
>>  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.
>>
>>  Thanks!!
>>  Corentin
>>
>>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140620/96bef5b3/attachment.html>


More information about the Haskell-Cafe mailing list