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? (aditya siram)
2. Re: Hints on how to remove unsafePerformIO from my
function? (David McBride)
3. Parsing Ambiguous Languages (Alex Rozenshteyn)
4. Re: Parsing Ambiguous Languages (Stephen Tetley)
5. Re: Re: Enforcing Monad Laws (Jorden M)
6. Re: parsec question (Michael Mossey)
----------------------------------------------------------------------
Message: 1
Date: Mon, 19 Jul 2010 12:50:34 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Hints on how to remove
unsafePerformIO from my function?
To: David McBride <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Have you looked at the Real World Haskell example [1] for reading from
a UDP socket? In the inner "procMessages" the authors seem to show
how to read one packet at a time without using unsafePerformIO.
-deech
[1] http://book.realworldhaskell.org/read/sockets-and-syslog.html in
the section marked "UDP Syslog Server"
On Mon, Jul 19, 2010 at 9:07 AM, 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
>
>
------------------------------
Message: 2
Date: Mon, 19 Jul 2010 13:58:19 -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"
Yeah I ended up doing pretty much what they do. The problem was I thought I
could collect all the IO actions one by one into an array and then just map
some other IO action over the array, but apparently the IO monad doesn't
like being lazy.
What you end up having to do is do one IO action at a time, getting the udp,
then sending it over the tchan immediately before attempting to fetch the
next udp packet. I ended up with:
fetchUDPSIP :: TChan a -> TChan B.ByteString -> IO ()
fetchUDPSIP commands chan = do
sock <- getUDPSocket 5060
forever $ getUDP sock >>= atomically . writeTChan chan
Which is perfectly fine. Thanks.
On Mon, Jul 19, 2010 at 1:50 PM, aditya siram <[email protected]>wrote:
> Have you looked at the Real World Haskell example [1] for reading from
> a UDP socket? In the inner "procMessages" the authors seem to show
> how to read one packet at a time without using unsafePerformIO.
>
> -deech
>
> [1] http://book.realworldhaskell.org/read/sockets-and-syslog.html in
> the section marked "UDP Syslog Server"
>
>
> On Mon, Jul 19, 2010 at 9:07 AM, 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/5dfbb49e/attachment-0001.html
------------------------------
Message: 3
Date: Mon, 19 Jul 2010 21:39:18 +0300
From: Alex Rozenshteyn <[email protected]>
Subject: [Haskell-beginners] Parsing Ambiguous Languages
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
I was just wondering, is there a way to use parsec get all valid parses of
an ambiguous language?
A quick google said no, but I may have missed something.
If not, is there another, similar library which does?
If not, why not?
--
Alex R
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100719/16ab2e75/attachment-0001.html
------------------------------
Message: 4
Date: Mon, 19 Jul 2010 20:30:21 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Parsing Ambiguous Languages
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hello Alex
Choice in Parsec is left-biased - the alternative combinator (<|>)
will return the fist successful parse. For reasons see the paper [1] -
in a nutshell error reporting is hard for ambiguous parsers and space
leaks become a problem.
Happy has some support for GLR parsing, but it might not working in
the current release.
If your interest is via natural language processing you might want to
search for Peter Ljunglof's (umlauts on o) thesis - "Pure Functional
Parsing an advanced tutorial". It covers Chart parsing (extending
Earley parsing) and GLR parsing. All source is within the paper.
[1] Daan Leijen & Erik Meijer
Parsec: Direct Style Monadic Parser Combinators For The Real World
------------------------------
Message: 5
Date: Mon, 19 Jul 2010 20:25:18 -0400
From: Jorden M <[email protected]>
Subject: Re: [Haskell-beginners] Re: Enforcing Monad Laws
To: Ozgur Akgun <[email protected]>
Cc: Heinrich Apfelmus <[email protected]>,
[email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On Mon, Jul 19, 2010 at 6:05 AM, Ozgur Akgun <[email protected]> wrote:
> On 4 July 2010 16:41, Jorden M <[email protected]> wrote:
>>
>> On Sun, Jul 4, 2010 at 11:16 AM, Daniel Fischer
>> <[email protected]> wrote:
>> > On Sunday 04 July 2010 16:05:48, Jorden M wrote:
>> >> > Now that I've had a really short look at Axioms, I think the Haskell
>> >> > equivalent would be QuickCheck properties. After all, Axioms are not
>> >> > enforced by the compiler, their only effect is documentation.
>> >> > Granted,
>> >> > they
>> >>
>> >> Really? I thought they were.
>> >>
>> >
>> > I think that's not even possible in general.
>>
>> It would equate to solving the Halting Problem, I suppose.
>
> Nope, it would just take long (ok, very long) to compute. Halting problem is
> undecidable in general.
>
No, I think Daniel is right -- it is not possible in general. It's
essentially verifying the behavior of a program, which is how the
Halting Problem is framed. Here we're looking at something more
general than `is the behavior of this program such that it halts?'.
------------------------------
Message: 6
Date: Mon, 19 Jul 2010 18:59:54 -0700
From: Michael Mossey <[email protected]>
Subject: Re: [Haskell-beginners] parsec question
To: David Virebayre <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
In any case, thanks to David and Stephen for helping with my problem.
Either solution is a neat improvement and an illustration for how the
language can be used.
Mike
David Virebayre wrote:
> 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.
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 25, Issue 45
*****************************************