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:  parsec question (David Virebayre)
   2. Re:  parsec question (Stephen Tetley)
   3. Re:  parsec question (David Virebayre)
   4.  Hints on how to remove unsafePerformIO from my   function?
      (David McBride)
   5. Re:  Hints on how to remove unsafePerformIO from  my
      function? (Benjamin Edwards)
   6. Re:  Hints on how to remove unsafePerformIO from  my
      function? (David McBride)


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

Message: 1
Date: Mon, 19 Jul 2010 13:05:06 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] parsec question
To: Stephen Tetley <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Mon, Jul 19, 2010 at 11:40 AM, Stephen Tetley
<[email protected]> wrote:
> Parsec has the CharParser - /integer/ - to avoid "many1 digit" and the like.

Note that he doesn't want "123456" to parse as the integer 123456, but
rather as the list of digits [ 1,2,3,4,5,6 ].

David.


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

Message: 2
Date: Mon, 19 Jul 2010 13:10:41 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] parsec question
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On 19 July 2010 12:05, David Virebayre <[email protected]> wrote:

> Note that he doesn't want "123456" to parse as the integer 123456, but
> rather as the list of digits [ 1,2,3,4,5,6 ].

Fair enough, I'd swap /digitToInt/ for read though...

digit1 :: Parser Int
digit1 = liftM digitToInt digit

digitList :: Parser [Int]
digitList = many digit1

digitToInt should do less work than read - running read is effectively
re-parsing the digits you have already parsed.

Best wishes

Stephen


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

Message: 3
Date: Mon, 19 Jul 2010 14:28:14 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] parsec question
To: Stephen Tetley <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Mon, Jul 19, 2010 at 2:10 PM, Stephen Tetley
<[email protected]> wrote:
> On 19 July 2010 12:05, David Virebayre <[email protected]> wrote:
>
>> Note that he doesn't want "123456" to parse as the integer 123456, but
>> rather as the list of digits [ 1,2,3,4,5,6 ].
>
> Fair enough, I'd swap /digitToInt/ for read though...

Of course ! I just didn't know that function existed :) Now that I
think of it, that's not a good excuse. Converting a single char to an
int is not difficult, I just had made a quick reply without thinking
too much.

David.


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

Message: 4
Date: Mon, 19 Jul 2010 10:07:52 -0400
From: David McBride <[email protected]>
Subject: [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"

I am writing a voip server to take advantage of haskells awesome threading
and parsing ability.  At first everything was going great, but my thread
that fetches udp makes use of unsafePerformIO:

fetchUDPSIP :: TChan B.ByteString -> IO ()
fetchUDPSIP chan = do
  sock <- getUDPSocket 5060
  let results = (unstrict . repeat . getUDP) sock
  mapM_ (atomically . writeTChan chan) results
  where
    unstrict [] = []
    unstrict (x:xs) = unsafePerformIO x:unstrict xs


It fetches it from a socket, and then writes it to a TChan.  This results in
a stream of bytestrings that another thread can read from.  If I don't use
unsafePerformIO, then it tries to read all possible packets before returning
anything, and so it never writes to the TChan at all.  The problem with
doing it this way is that unsafePerformIO apparently stops every other
thread from doing anything while it is waiting for a packet.

But I can't think of a way to rewrite this function to do what I want.  I'm
kind of new to this, does anyone have any hints that could help me out?

Here's a simple version without any of the implementation details:

fetchLine = do
  let results = (unstrict . repeat) getLine
  mapM_ putStrLn results
  where
    unstrict [] = []
    unstrict (x:xs) = unsafePerformIO x:unstrict xs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100719/4e76a4c7/attachment-0001.html

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

Message: 5
Date: Mon, 19 Jul 2010 16:12:32 +0200
From: Benjamin Edwards <[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"

fork it into a thread and have it run on a loop, yielding if it can't read
any data from the udp socket?

On 19 July 2010 16:07, David McBride <[email protected]> wrote:

> I am writing a voip server to take advantage of haskells awesome threading
> and parsing ability.  At first everything was going great, but my thread
> that fetches udp makes use of unsafePerformIO:
>
> fetchUDPSIP :: TChan B.ByteString -> IO ()
> fetchUDPSIP chan = do
>   sock <- getUDPSocket 5060
>   let results = (unstrict . repeat . getUDP) sock
>   mapM_ (atomically . writeTChan chan) results
>   where
>     unstrict [] = []
>     unstrict (x:xs) = unsafePerformIO x:unstrict xs
>
>
> It fetches it from a socket, and then writes it to a TChan.  This results
> in a stream of bytestrings that another thread can read from.  If I don't
> use unsafePerformIO, then it tries to read all possible packets before
> returning anything, and so it never writes to the TChan at all.  The problem
> with doing it this way is that unsafePerformIO apparently stops every other
> thread from doing anything while it is waiting for a packet.
>
> But I can't think of a way to rewrite this function to do what I want.  I'm
> kind of new to this, does anyone have any hints that could help me out?
>
> Here's a simple version without any of the implementation details:
>
> fetchLine = do
>   let results = (unstrict . repeat) getLine
>   mapM_ putStrLn results
>   where
>     unstrict [] = []
>     unstrict (x:xs) = unsafePerformIO x:unstrict xs
>
> _______________________________________________
> 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/8d12f717/attachment-0001.html

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

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

Well, I thought about that, but I can't find anything in the network.socket
library that would allow me to see if there is any data ready to be read
from.

But besides that, wouldn't that cause a busy wait as the thread constantly
failed to read and yielded over and over again until there was a new
packet?  I'd rather if this thread chilled out until something worthwhile
occurs.

On Mon, Jul 19, 2010 at 10:12 AM, Benjamin Edwards
<[email protected]>wrote:

> fork it into a thread and have it run on a loop, yielding if it can't read
> any data from the udp socket?
>
> On 19 July 2010 16:07, David McBride <[email protected]> wrote:
>
>> I am writing a voip server to take advantage of haskells awesome threading
>> and parsing ability.  At first everything was going great, but my thread
>> that fetches udp makes use of unsafePerformIO:
>>
>> fetchUDPSIP :: TChan B.ByteString -> IO ()
>> fetchUDPSIP chan = do
>>   sock <- getUDPSocket 5060
>>   let results = (unstrict . repeat . getUDP) sock
>>   mapM_ (atomically . writeTChan chan) results
>>   where
>>     unstrict [] = []
>>     unstrict (x:xs) = unsafePerformIO x:unstrict xs
>>
>>
>> It fetches it from a socket, and then writes it to a TChan.  This results
>> in a stream of bytestrings that another thread can read from.  If I don't
>> use unsafePerformIO, then it tries to read all possible packets before
>> returning anything, and so it never writes to the TChan at all.  The problem
>> with doing it this way is that unsafePerformIO apparently stops every other
>> thread from doing anything while it is waiting for a packet.
>>
>> But I can't think of a way to rewrite this function to do what I want.
>> I'm kind of new to this, does anyone have any hints that could help me out?
>>
>> Here's a simple version without any of the implementation details:
>>
>> fetchLine = do
>>   let results = (unstrict . repeat) getLine
>>   mapM_ putStrLn results
>>   where
>>     unstrict [] = []
>>     unstrict (x:xs) = unsafePerformIO x:unstrict xs
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> 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/a44f85e4/attachment.html

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

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


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

Reply via email to