[Haskell-cafe] Filtering a big list into the IO monad

Chris Kuklewicz haskell at list.mightyreason.com
Thu Aug 3 14:03:15 EDT 2006


Gabriel Sztorc wrote:
> Hello,
> 
> I want to filter a list with a predicate that returns a IO value, 
> something that filterM is supposed to do. The problem is, filterM 
> overflows the stack for really big lists and I couldn't come up with a 
> simple replacement for filterM that would work for lists of any size 
> (the truth is, I can't come up with anything at all :).
> 
> The question is: how to do it? Any help is appreciated.

What is the predicate computing?  Does it have side effects?  Does the order of 
evaluation matter?

A dangerous solution is to use unsafeInterleaveIO or unsafePerformIO to change 
your predicate to look like a pure function...



More information about the Haskell-Cafe mailing list