
On Wed, 2006-07-05 at 12:08 +0100, Neil Mitchell wrote:
Hi,
What I want to know is the generic way to force an entire String (or other list, perhaps from hGetContents) to be evaluated (read into RAM, I guess) so the underlying file can be closed.... and do it right now. What I have done in the past is to take the length of the string, and test the length in some way - although I guess you could call seq on the length.
evaluate is for just that purpose. evaluate (length input) from the docs: http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.htm... evaluate :: a -> IO a Forces its argument to be evaluated, and returns the result in the IO monad. It can be used to order evaluation with respect to other IO operations; its semantics are given by evaluate undefined `seq` return () ==> return () catch (evaluate undefined) (\e -> return ()) ==> return () NOTE: (evaluate a) is not the same as (a `seq` return a). Duncan