From: shelarcy <she...@gm...> - 2008-03-14 10:53:59
|
Hi, On Fri, 14 Mar 2008 19:24:12 +0900, Eric Y. Kow <eri...@gm...> wrote: > Here's my implementation of it. Does it look sane to you? Any comments > from wxhaskell developers? > > withImageData :: Image a -> (Ptr () -> IO b) -> IO b > withImageData image f = do > pixels <- imageGetData image > x <- f pixels > x `seq` image `seq` return x > > The seqs are there out of pure superstition (i.e. Eric doesn't know how > Haskell works); basically, I want to make sure we're holding on to image > as long as we need to, so at least until we know what 'x' is. "a seq b" doesn't guarantee that evaluate a before b. If we want to do that, we must use Control.Parallel's pseq. http://www.haskell.org/ghc/docs/6.8.2/html/libraries/parallel/Control-Parallel.html#v%3Apseq Or to use $! operator in monad, like this. return $! x return $! image return x Best Regards, -- shelarcy <shelarcy hotmail.co.jp> http://page.freett.com/shelarcy/ |