Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Hints on how to remove unsafePerformIO from  my
      function? (Stephen Tetley)
   2. Re:  Hints on how to remove unsafePerformIO from  my
      function? (David McBride)
   3. Re:  Hints on how to remove unsafePerformIO from  my
      function? (David McBride)
   4. Re:  Hints on how to remove unsafePerformIO       from my function?
      (Brent Yorgey)


----------------------------------------------------------------------

Message: 1
Date: Mon, 19 Jul 2010 15:41:31 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Hints on how to remove
        unsafePerformIO from    my function?
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

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.


------------------------------

Message: 2
Date: Mon, 19 Jul 2010 11:09:02 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] Hints on how to remove
        unsafePerformIO from    my function?
To: Stephen Tetley <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

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
<[email protected]>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
> [email protected]
> 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-0001.html

------------------------------

Message: 3
Date: Mon, 19 Jul 2010 11:18:28 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] Hints on how to remove
        unsafePerformIO from    my function?
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Okay, I figured this out on my own.  This isn't as elegant but it definitely
works:

fetchUDPSIP :: TChan a -> TChan B.ByteString -> IO ()
fetchUDPSIP commands chan = do
  sock <- getUDPSocket 5060
  loop sock
  where
    loop sock = do
      result <- getUDP sock
      (atomically . writeTChan chan) result
      loop sock

fetchLine = do
  loop
  where
    loop = do
      result <- Prelude.getLine
      Prelude.putStrLn result
      loop


On Mon, Jul 19, 2010 at 11:09 AM, David McBride <[email protected]>wrote:

> 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 <[email protected]
> > 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
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100719/df669992/attachment-0001.html

------------------------------

Message: 4
Date: Mon, 19 Jul 2010 17:20:34 +0100
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Hints on how to remove
        unsafePerformIO from my function?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Mon, Jul 19, 2010 at 11:18:28AM -0400, David McBride wrote:
> Okay, I figured this out on my own.  This isn't as elegant but it definitely
> works:
> 

By the way, your code can be simplified using forever; these ought to
be equivalent:

> fetchUDPSIP :: TChan a -> TChan B.ByteString -> IO ()
> fetchUDPSIP commands chan = do
>   sock <- getUDPSocket 5060
>   forever $ do
>     result <- getUDP sock
>     (atomically . writeTChan chan) result
> 
> fetchLine = forever $ do
>   result <- Prelude.getLine
>   Prelude.putStrLn result

-Brent


------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 25, Issue 44
*****************************************

Reply via email to