Send Beginners mailing list submissions to beginners@haskell.org 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 beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: Problem with catching error (Alexey G) 2. Re: A question on types (Mike Meyer) 3. Re: A question on types (C K Kashyap) 4. Re: Network client - reading and writing to a socket (Manfred Lotz) 5. Suggestions for creating a "bind" function that can be applied to different things? (Costello, Roger L.) 6. Re: Suggestions for creating a "bind" function that can be applied to different things? (Antoine Latter) 7. Re: Network client - reading and writing to a socket (Chadda? Fouch?) 8. linker error, protips welcome (Michael Litchard) ---------------------------------------------------------------------- Message: 1 Date: Mon, 1 Aug 2011 16:29:16 +0300 From: Alexey G <kreed...@gmail.com> Subject: Re: [Haskell-beginners] Problem with catching error To: Daniel Fischer <daniel.is.fisc...@googlemail.com> Cc: beginners@haskell.org Message-ID: <caordkxtbknlt6gd0ounm1fbjsgod_yoo67rb+_r+gkzsx-s...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Thank you for help. I didn't know about the "reads" function. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110801/7e29a5cd/attachment-0001.htm> ------------------------------ Message: 2 Date: Mon, 1 Aug 2011 09:17:44 -0700 From: Mike Meyer <m...@mired.org> Subject: Re: [Haskell-beginners] A question on types To: C K Kashyap <ckkash...@gmail.com> Cc: beginners <beginners@haskell.org> Message-ID: <CAD=7U2B=bcdngptm8h8-x3wxxxjoxgpclbtzg1+fjgzjsrm...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" On Mon, Aug 1, 2011 at 12:52 AM, C K Kashyap <ckkash...@gmail.com> wrote: > Hi, > To clarify my understanding, I created this table > > | | weak | strong | > |---------+------+---------| > | dynamic | perl | Ruby | > | static | C | Haskell | > |---------+------+---------| > > Could someone please ratify this? > Static vs. dynamic typing is pretty well always understood to mean compile time vs. run time type checking, so you've got that one. On the other hand, there's no widely accepted definition of strong vs. weak typing. So I'm pretty sure there's at least one definition for which you're right. Both C and Ruby fit definitions for both strong and weak typing, and there are probably definitions that have them swap places. Perl and Haskell may always be considered weakly and strongly typed (respectively), but I wouldn't bet on it. <mike -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110801/d64e7169/attachment-0001.htm> ------------------------------ Message: 3 Date: Mon, 1 Aug 2011 22:22:57 +0530 From: C K Kashyap <ckkash...@gmail.com> Subject: Re: [Haskell-beginners] A question on types To: Mike Meyer <m...@mired.org> Cc: beginners <beginners@haskell.org> Message-ID: <CAGdT1grDLmA0XeFCtev8EprhKRQ8zGBD=6ky+vr4vcutjp_...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Thank you folks... -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110801/c87a386d/attachment-0001.htm> ------------------------------ Message: 4 Date: Mon, 1 Aug 2011 21:16:46 +0200 From: Manfred Lotz <manfred.l...@arcor.de> Subject: Re: [Haskell-beginners] Network client - reading and writing to a socket To: beginners@haskell.org Message-ID: <20110801211646.622ab...@arcor.com> Content-Type: text/plain; charset=US-ASCII On Sun, 31 Jul 2011 15:14:23 -0400 Patrick LeBoutillier <patrick.leboutill...@gmail.com> wrote: > Manfred, > > > The problem is that the message itself is some 30K big and I only > > get some 16K of the message. > > > > How could I force to get the whole message? > > My guess is that you can't. This call: > > c' <- B.hGetNonBlocking h 40000 > > tries to read as much as it can (up to 40000 bytes) but it won't block > to wait for data. Perhaps the rest of your message is in a different > TCP packet or delayed or whatever, but I think you have to keep on > reading (and maybe block) until you know you have read the entire > message. The IMAP specs will tell you how to identify the "end of the > message". > > BTW: This issue is not Haskell specific. If you implement the same > code in C, Perl or Java you will have to deal with the same problem. > When you read from a socket, there is no general way of knowing that > the other side has sent everything. > Hmm. I'm not quite sure you are fully right. On the one hand I believe that this could be an issue which arises in python/perl etc. as well. On the other hand I believe it should be possible to receive from a socket what is available at a certain point of time. I found this link http://sequence.complete.org/node/257, and when I run the code I get the full message from the imap server even if the message is a couple of megabytes big. I have to figure out how to use the code for my need as I do not get the input from the keyboard. As a haskell beginner things like this are not always trivial. -- Thanks, Manfred > > Patrick > > > > > -- > > Manfred > > > > > > > > _______________________________________________ > > Beginners mailing list > > Beginners@haskell.org > > http://www.haskell.org/mailman/listinfo/beginners > > > > > -- Manfred ------------------------------ Message: 5 Date: Mon, 1 Aug 2011 19:44:38 -0400 From: "Costello, Roger L." <coste...@mitre.org> Subject: [Haskell-beginners] Suggestions for creating a "bind" function that can be applied to different things? To: "beginners@haskell.org" <beginners@haskell.org> Message-ID: <9e51f88d5247b648908850c35a3bbb50059df9a...@imcmbx3.mitre.org> Content-Type: text/plain; charset="us-ascii" Hi Folks, When I say: "Let x be of datatype Int." I think the proper terminology is "bind". That is, I bind the name "x" to the Int datatype. Is that the correct terminology? Assuming it is, I would like to bind a name to many different things. I seek your suggestions on how to do this. First let dt1, dt2, dt3, dt4 be "DataTypes": dt1, dt2, dt3, dt4 :: DataType And let "Name" be synonymous with String: type Name = String And let title, author, date, cost be "Elements": title, author, date, cost, book :: Element I would like a "bind" function that binds a Name to a DataType to create an Element: bind :: Name -> DataType -> Element Here are a few examples of using bind to create Elements: title = bind "Title" dt4 author = bind "Author" dt4 date = bind "Date" dt4 I would also like to bind a Name to a DataType to create an "Attribute": bind :: Name -> DataType -> Attribute Here's an example of using bind to create an Attribute: currency = bind "Currency" dt3 And I'd like to bind an Attribute to an Element: bind :: Attribute -> Element -> Element Here's an example of binding the currency Attribute to a cost Element: cost = bind currency (bind "Cost" dt1) Finally, I'd like to create an Element by binding a Name to a list of Elements: bind :: Name -> [Element] -> Element Here's an example of this: book = bind "Book" [title, author, date, cost] As you see, I'd like to "bind" to lots of different things. But I can't create multiple functions with the same name, "bind". And I'd rather not create a function for each thing that I want to bind to, e.g., elementBind, attributeBind, attributeToElementBind, multipleElementsBind. There must be an elegant solution. What is your suggestion? /Roger ------------------------------ Message: 6 Date: Mon, 1 Aug 2011 19:27:14 -0500 From: Antoine Latter <aslat...@gmail.com> Subject: Re: [Haskell-beginners] Suggestions for creating a "bind" function that can be applied to different things? To: "Costello, Roger L." <coste...@mitre.org> Cc: "beginners@haskell.org" <beginners@haskell.org> Message-ID: <cakjsnqgpgbrwcnzrk6bzrejmjtezos1arn7qfrqmyvbnx19...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Mon, Aug 1, 2011 at 6:44 PM, Costello, Roger L. <coste...@mitre.org> wrote: > Hi Folks, > > When I say: > > ? ?"Let x be of datatype Int." > > ?I think the proper terminology is "bind". That is, I bind the name "x" to > the Int datatype. > > Is that the correct terminology? > When someone uses the terminology "bind" I assume that they are referring to binding a value to a name, not associating a typing rule with the name. So in the haskell declaration: > let f x = show x I would use the word "binding" to refer to the introduction of the variable named "x" as used in the body of the function "f". That might be an over-limited view of the concept, and really this only applies to to the study of the structure of programming languages themselves - I feel like you might be talking about something different. I don't quite understanding what you're after in the rest of the post. Are you implementing a compiler? Some sort of abstract analysis work? What is your "DataType" type meant to represent? What is your "Element" type meant to represent? Antoine ------------------------------ Message: 7 Date: Tue, 2 Aug 2011 02:59:44 +0200 From: Chadda? Fouch? <chaddai.fou...@gmail.com> Subject: Re: [Haskell-beginners] Network client - reading and writing to a socket To: Manfred Lotz <manfred.l...@arcor.de> Cc: beginners@haskell.org Message-ID: <canfjzrzkcegct-xuywta7spc5f558nyumhze8mv4cxubsxq...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Mon, Aug 1, 2011 at 9:16 PM, Manfred Lotz <manfred.l...@arcor.de> wrote: > On Sun, 31 Jul 2011 15:14:23 -0400 > Patrick LeBoutillier <patrick.leboutill...@gmail.com> wrote: > >> Manfred, >> >> > The problem is that the message itself is some 30K big and I only >> > get some 16K of the message. >> > >> > How could I force to get the whole message? >> >> My guess is that you can't. This call: >> >> c' <- B.hGetNonBlocking h 40000 >> >> tries to read as much as it can (up to 40000 bytes) but it won't block >> to wait for data. Perhaps the rest of your message is in a different >> TCP packet or delayed or whatever, but I think you have to keep on >> reading (and maybe block) until you know you have read the entire >> message. The IMAP specs will tell you how to identify the "end of the >> message". >> >> BTW: This issue is not Haskell specific. If you implement the same >> code in C, Perl or Java you will have to deal with the same problem. >> When you read from a socket, there is no general way of knowing that >> the other side has sent everything. >> > > Hmm. I'm not quite sure you are fully right. On the one hand I believe > that this could be an issue which arises in python/perl etc. as well. > On the other hand I believe it should be possible to receive from a > socket what is available at a certain point of time. Yes and that's exactly what you have done : your hGetLine blocks until there is something to read on the socket and then your hGetNonBlocking gets *everything* there is to read on this socket at this exact moment... Except as had been said by others that your message has been split into several packets and they're not all there when you hGet. What you want is not "what is available at a certain point of time", you want to read a whole message, except that this "message" notion is only in your head (and in a specific protocol, IMAP here) it has no direct relevance to how things happens on the network. > I found this link http://sequence.complete.org/node/257, and when I run > the code I get the full message from the imap server even if the > message is a couple of megabytes big. Of course you get the whole message ! This code try to read (with blocking calls) forever what's on your socket, it reads it, send it on a TChan and then retry reading it, bit by bit it gets your whole message, of course it has no idea that it got your whole message and if nothing is done it will continue to wait on your socket for all eternity... The key point is this function : > listenLoop :: IO a -> TChan a -> IO () > listenLoop act chan = > sequence_ (repeat (act >>= atomically . writeTChan chan)) This does not stop short of an exception. Two of those loops are started each in their own thread (so that they don't block the rest of the program) to read stdin and a socket respectively. > I have to figure out how to use the code for my need as I do not get > the input from the keyboard. This code is probably not doing what you want, this is a toy example where most of the complexity comes from handling two source of input simultaneously and collating their answer on the same TChan. Its main problem is that it don't even try to read messages, it just read everything and doesn't know when it's finished. You need to listen to David's advice and read a bit on the protocol you're trying to handle and how it encode the notion of message, how it signals that the message has ended. -- Jeda? ------------------------------ Message: 8 Date: Mon, 1 Aug 2011 20:36:58 -0700 From: Michael Litchard <mich...@schmong.org> Subject: [Haskell-beginners] linker error, protips welcome To: beginners@haskell.org Message-ID: <CAEzeKYq56akZ8bTmVguvGkZk5oOiJ=b683FLjLOq=rpn4vm...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 ghci is trying to load both network-2.3.0.2 and network-2.3.0.4 I don't have 2.3.02 installed I checked package.conf, and it's not there. What can I check to see what's going on? hcifoo> :main Loading package bytestring-0.9.1.10 ... linking ... done. Loading package transformers-0.2.2.0 ... linking ... done. Loading package mtl-2.0.1.0 ... linking ... done. Loading package parsec-3.1.1 ... linking ... done. Loading package unix-2.4.2.0 ... linking ... done. Loading package network-2.3.0.2 ... linking ... done. Loading package array-0.3.0.2 ... linking ... done. Loading package old-locale-1.0.0.2 ... linking ... done. Loading package old-time-1.0.0.6 ... linking ... done. Loading package HTTP-4000.1.1 ... linking ... done. Loading package containers-0.4.0.0 ... linking ... done. Loading package deepseq-1.1.0.2 ... linking ... done. Loading package text-0.11.0.6 ... linking ... done. Loading package curl-1.3.7 ... linking ... done. Loading package HUnit-1.2.2.3 ... linking ... done. Loading package filepath-1.2.0.0 ... linking ... done. Loading package directory-1.1.0.0 ... linking ... done. Loading package process-1.0.1.5 ... linking ... done. Loading package time-1.2.0.3 ... linking ... done. Loading package random-1.0.0.3 ... linking ... done. Loading package haskell98-1.1.0.1 ... linking ... done. Loading package network-2.3.0.4 ... GHCi runtime linker: fatal error: I found a duplicate definition for symbol my_inet_ntoa whilst processing object file /home/mlitchard/.cabal/lib/network-2.3.0.4/ghc-7.0.3/HSnetwork-2.3.0.4.o This could be caused by: * Loading two different object files which export the same symbol * Specifying the same object file twice on the GHCi command line * An incorrect `package.conf' entry, causing some object to be loaded twice. GHCi cannot safely continue in this situation. Exiting now. Sorry. ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 38, Issue 3 ****************************************