Re: [Haskell-cafe] Simple network client

2008-02-01 Thread Jules Bean
Jonathan Cast wrote: On 31 Jan 2008, at 1:23 AM, Reinier Lamers wrote: Bayley, Alistair wrote: More than one person has posted previously about the flaws and traps of lazy IO. A common position seems to be don't do lazy IO. Still, when I was browsing the Haskell' wiki a few days ago, I

Re: [Haskell-cafe] Simple network client

2008-01-31 Thread Reinier Lamers
Bayley, Alistair wrote: More than one person has posted previously about the flaws and traps of lazy IO. A common position seems to be don't do lazy IO. Still, when I was browsing the Haskell' wiki a few days ago, I couldn't find any proposal to remove lazy I/O or move it into some special

Re: [Haskell-cafe] Simple network client

2008-01-31 Thread Gary Bickford
Wasn't there a Linux file system (possibly a FUSE user-space one) that worked on writable CDs? IIRC it worked by marking the previous copy of the file as erased, and writing a new copy. On Wed, 2008-01-30 at 23:05 -0500, [EMAIL PROTECTED] wrote: PS: I would love to see an immutable filesystem

Re: [Haskell-cafe] Simple network client

2008-01-31 Thread Adam Langley
On Jan 31, 2008 5:07 AM, Gary Bickford [EMAIL PROTECTED] wrote: Wasn't there a Linux file system (possibly a FUSE user-space one) that worked on writable CDs? IIRC it worked by marking the previous copy of the file as erased, and writing a new copy. Probably you're thinking of layering a

Re: [Haskell-cafe] Simple network client

2008-01-31 Thread Jonathan Cast
On 31 Jan 2008, at 1:23 AM, Reinier Lamers wrote: Bayley, Alistair wrote: More than one person has posted previously about the flaws and traps of lazy IO. A common position seems to be don't do lazy IO. Still, when I was browsing the Haskell' wiki a few days ago, I couldn't find any

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Timo B. Hübel
On Wednesday 30 January 2008 13:03:27 you wrote: Just don't use hGetContents in any serious code, or any program longer than 4 lines. What else do you suggest? I just want to read something out of the socket without knowing it's length beforehand (my example here used ordinary Strings, but

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Jules Bean
Your bug here is hGetContents. Don't use it. Lazy IO gremlins bite once again. Your client is waiting for the server to close the socket before it prints anything. But your server is waiting for the client to close the socket before *it* prints anything. Just don't use hGetContents in any

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Reinier Lamers
Timo B. Hübel wrote: On Wednesday 30 January 2008 13:03:27 you wrote: Just don't use hGetContents in any serious code, or any program longer than 4 lines. What else do you suggest? I just want to read something out of the socket without knowing it's length beforehand (my example here

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Jules Bean
Timo B. Hübel wrote: On Wednesday 30 January 2008 13:32:42 you wrote: Timo B. Hübel wrote: On Wednesday 30 January 2008 13:03:27 you wrote: Just don't use hGetContents in any serious code, or any program longer than 4 lines. What else do you suggest? I just want to read something out of the

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Timo B. Hübel
On Wednesday 30 January 2008 13:32:42 you wrote: Timo B. Hübel wrote: On Wednesday 30 January 2008 13:03:27 you wrote: Just don't use hGetContents in any serious code, or any program longer than 4 lines. What else do you suggest? I just want to read something out of the socket without

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Jules Bean
Timo B. Hübel wrote: On Wednesday 30 January 2008 13:51:58 you wrote: Okay, but then I have to make sure that my strings won't contain any newline characters, right? If this is the case, another question raises up: I am using Data.Binary to do the serialization of my data structures to

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Timo B. Hübel
On Wednesday 30 January 2008 14:09:31 you wrote: This sounds good, but don't I throw away all (possible) performance gains of transmitting ByteStrings directly when using show/read to convert them to ordinary strings and back? Probably not all of them, but some of them, definitely. If

RE: [Haskell-cafe] Simple network client

2008-01-30 Thread Peter Verswyvelen
To: Timo B. Hübel Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Simple network client Your bug here is hGetContents. Don't use it. Lazy IO gremlins bite once again. Your client is waiting for the server to close the socket before it prints anything. But your server

RE: [Haskell-cafe] Simple network client

2008-01-30 Thread Bayley, Alistair
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Verswyvelen As a newbie I made a nice little program that called readFile and writeFile on the same filename, but of course the file handle of the readFile was not closed yet = access denied. A nice case of getting

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Bryan O'Sullivan
Peter Verswyvelen wrote: Then I tried the seq hack to force the handle opened by readFile to be closed, but that did not seem to work either. For example, the following still gave access denied: main = do cs - readFile L:/Foo.txt writeFile L:/Foo.txt $ seq (length cs) cs This is

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Adam Langley
On Jan 30, 2008 4:32 AM, Jules Bean [EMAIL PROTECTED] wrote: The third, but more sophisticated answer is to use non-blocking IO, read 'only what is available', decide if it's enough to process, if not store it in some local buffer until next time. This is much more work and easy to implement

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Judah Jacobson
On Jan 30, 2008 8:31 AM, Bryan O'Sullivan [EMAIL PROTECTED] wrote: Peter Verswyvelen wrote: Then I tried the seq hack to force the handle opened by readFile to be closed, but that did not seem to work either. For example, the following still gave access denied: main = do cs -

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Jules Bean
Judah Jacobson wrote: On Jan 30, 2008 8:31 AM, Bryan O'Sullivan [EMAIL PROTECTED] wrote: Peter Verswyvelen wrote: Then I tried the seq hack to force the handle opened by readFile to be closed, but that did not seem to work either. For example, the following still gave access denied: main =

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Gary Bickford
One rather funky but effective solution might be to use the tftp protocol. No security, but simple, flexible and efficient. I think there are C libraries that implement it. This would take care of handshaking binary data. I have no idea if anyone has ever used it in Haskell. GB On Wed,

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Bryan O'Sullivan
Adam Langley wrote: Also, if you want the above approach (read a bit, see if it's enough), see IncrementalGet in the binary-strict package which is a Get with a continuation monad that stops when it runs out of bytes and returns a continuation that you can give more data to in the future.

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Adam Langley
On Jan 30, 2008 12:04 PM, Bryan O'Sullivan [EMAIL PROTECTED] wrote: Adam Langley wrote: I'd have expected it to look more like this: data Result a = Failed String | Finished B.ByteString a | Partial (B.ByteString - Result a) (The change here is from a list to a

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Bryan O'Sullivan
Adam Langley wrote: On Jan 30, 2008 1:07 PM, Adam Langley [EMAIL PROTECTED] wrote: So, if I don't hear otherwise soon, I'll probably push a new version of binary-strict later on today with the interface above. It's in the darcs now, http://darcs.imperialviolet.org/binary-strict Thanks!

RE: [Haskell-cafe] Simple network client

2008-01-30 Thread Peter Verswyvelen
And even better is main = do cs - strictReadFile L:/Foo.txt writeFile L:/Foo.txt cs Yes. By making these mistakes I understand the problem very well now. But it *is* hard to see if the function in question is strict or lazy. For example, the problem to me appears to be that this

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Adam Langley
On Jan 30, 2008 1:07 PM, Adam Langley [EMAIL PROTECTED] wrote: So, if I don't hear otherwise soon, I'll probably push a new version of binary-strict later on today with the interface above. It's in the darcs now, http://darcs.imperialviolet.org/binary-strict AGL -- Adam Langley

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Dan Weston
Peter Verswyvelen wrote: main = do cs - getLine putStrLn (Hello ++cs) looks so much like main = do cs - readFile foo writeFile foo cs but in the first one cs is strict, while the second it is lazy... But that's not obvious. Now I'm confused (which happens

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Jules Bean
Dan Weston wrote: Now I'm confused (which happens quite a lot, I'm afraid!) Prelude readFile undefined *** Exception: Prelude.undefined Prelude readFile undefined = \cs - putStrLn Hello *** Exception: Prelude.undefined It seems that readFile is strict in its argument. As for getLine, it has

Re: [Haskell-cafe] Simple network client

2008-01-30 Thread Evan Laforge
PS: I would love to see an immutable filesystem that does not allow writing to files, it only creates new files and garbage collects files that have no incoming reference anymore... Just like a garbage collected heap, and a bit like an OLAP databases (as far as I remember my DB theory...)

Re: [Haskell-cafe] Simple network client

2008-01-29 Thread Mads Lindstrøm
Hi Timo B. Hübel wrote: Hello, I am using the very simple interactTCP example from [1] to play around with Haskell network programming but I just can't get a simple client for that example to work (it works like a charm with my telnet client, as described in the article). This is

Re: [Haskell-cafe] Simple network client

2008-01-29 Thread Timo B. Hübel
On Tuesday 29 January 2008 14:44:42 Mads Lindstrøm wrote: If you replace the `putStrLn (show res)` with this:   mapM_ (\x - putStr (show x) hFlush stdout) res it works. Hm, unfortunately not for me (Linux, GHC 6.8.2) ... I _think_ the problem is that `putStrLn  (show res)` will wait until

Re: [Haskell-cafe] Simple network client

2008-01-29 Thread Timo B. Hübel
On Tuesday 29 January 2008 17:12:19 you wrote: There was a similar bug in lazy bytestring's hGetContents a while back which involve it waiting for a whole chunk and not returning short reads, but from watching the strace of this code, GHC is reading byte-by-byte (which is actually pretty dumb,

Re: [Haskell-cafe] Simple network client

2008-01-29 Thread Adam Langley
On Jan 29, 2008 6:28 AM, Timo B. Hübel [EMAIL PROTECTED] wrote: Hm, unfortunately not for me (Linux, GHC 6.8.2) ... That's odd, because it works for me on the exact same setup. There was a similar bug in lazy bytestring's hGetContents a while back which involve it waiting for a whole chunk and