[Haskell-beginners] Hints on how to remove unsafePerformIO from my function?

David McBride dmcbride at neondsl.com
Mon Jul 19 11:09:02 EDT 2010


I tried this:

fetchUDPSIP :: TChan a -> TChan B.ByteString -> IO ()
fetchUDPSIP commands chan = do
  sock <- getUDPSocket 5060
  results <- (mapM unsafeInterleaveIO . repeat . getUDP) sock
  mapM_ (atomically . writeTChan chan) results

fetchLine = do
  results <- (mapM unsafeInterleaveIO . repeat) Prelude.getLine
  mapM_ Prelude.putStrLn results

But it seems to have become strict again in that neither version will return
any results until it has gotten everything it can.

Also I'm not sure, but I'm pretty sure any "unsafe" function is still going
to have the original problem where it causes all other threads to stop while
it performs, so I don't think I can use unsafe anything at all and have my
program work properly.

On Mon, Jul 19, 2010 at 10:41 AM, Stephen Tetley
<stephen.tetley at gmail.com>wrote:

> How about unsafeInterleaveIO? - You might have to experiment where to
> put it, but you shouldn't need the local unstrict definition.
>
> Because it doesn't violate type safety it is considered less heinous
> than unsafePerformIO.
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100719/5406d765/attachment.html


More information about the Beginners mailing list