[Haskell-beginners] Lazy variant of sequence (or other way to approach problem)
Nathan Hüsken
nathan.huesken at posteo.de
Thu Sep 27 09:14:27 CEST 2012
On 09/27/2012 01:45 AM, Ertugrul Söylemez wrote:
> Nathan Hüsken <nathan.huesken at posteo.de> wrote:
>
>> In my (SDL based) haskell program, I do:
>>
>> events <- liftM ( takeWhile (/= NoEvent)) $ sequence $ repeat
>> pollEvent
>>
>> The execution of this never returns, I am guessing that is because
>> sequence evaluation never stops.
>>
>> But if sequence would be lazy (and assuming pollEvent returns NoEvent
>> at some point) this should stop, should it not?
>> Is there a lazy variant of sequence? Or am I missing something here
>> completely?
>
> The sequence function itself cannot be lazy, and there can't be a lazy
> variant of it.
I understand, that it is a bad Idea. But why is it impossible to have an
lazy sequence? Why can it not wait with the execution of the action for
the list elements to be evaluated?
> By the way, if your application is non-continuously rendered, which is
> suggested by your ignoring of NoEvent, you shouldn't use pollEvent at
> all.
The Idea of the line what to return all events that happened in the
current frame (which are to my understanding all events until pollEvent
returns NoEvent).
> Hope this helps.
Yes, thank you. I have to read into the Coroutine approach a little more
before to understand it :).
Best Regards,
Nathan
More information about the Beginners
mailing list