Lazy evaluation can sometimes be helpful here. I once wrote a
raytracer that computed the resulting image using a pure function that
returned a list of the RGB colors of the pixels: [(Word8, Word8,
Word8)]

When plotting the pixels to the screen in the IO monad, the value of
each pixel would be computed on demand, and so the image was shown
progressively as the calculations were performed.

I was new to haskell when I made this program and when I ran the
program for this first time I was expecting to experience a long pause
and then a display of the final image. I was very surprised to see
progressive rendering!

On Nov 29, 2007 12:03 AM, Andrew Coppin <[EMAIL PROTECTED]> wrote:
> In a "normal" programming language, you might write something like this:
>
>   for x = 1 to 1000000
>     print x
>     ...do slow complex stuff...
>   next x
>
> In Haskell, you're more likely to write something like
>
>   result k = filter my_weird_condition $ map strange_conversion $
> unfoldr ...
>
> That means that when you try to process the result, lots of processing
> happens, and your program just appears to lock up until a result is
> produced. So, like, how do you make it so that some kind of progress
> information is output while it's working? (Aside from dunking everything
> into the IO monad and ruining all your beautiful abstractions.) There
> doesn't seem to be a clean solution to this one...
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to