Hi,

On Fri, 14 Mar 2008 19:24:12 +0900, Eric Y. Kow <[EMAIL PROTECTED]> 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/

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
wxhaskell-users mailing list
wxhaskell-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxhaskell-users

Reply via email to