Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-16 Thread Tim Newsham
The problem is that you're closing the file twice. When you call any function of the getContents family, you assign to that function the responsibility to close the file, no sooner than it is no longer needed. Don't call hClose yourself, Bad Things will happen. If you close the file, the

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-16 Thread Matthew Brecknell
Tim Newsham: Why can't hClose be more... um... lazy? Lazy in what way? hGetContents already closes the OS handle when it reaches the end of file. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-13 Thread Andrew Coppin
Stefan O'Rear wrote: The problem is that you're closing the file twice. When you call any function of the getContents family, you assign to that function the responsibility to close the file, no sooner than it is no longer needed. Don't call hClose yourself, Bad Things will happen. Care to

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-13 Thread Stefan O'Rear
On Fri, Jul 13, 2007 at 07:59:22PM +0100, Andrew Coppin wrote: Stefan O'Rear wrote: The problem is that you're closing the file twice. When you call any function of the getContents family, you assign to that function the responsibility to close the file, no sooner than it is no longer needed.

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-13 Thread Andrew Coppin
Stefan O'Rear wrote: On Fri, Jul 13, 2007 at 07:59:22PM +0100, Andrew Coppin wrote: Care to elaborate on bad things? (I.e., will this just crash the program with an error, or will it do something more serious?) I must admit, I thought closing such a file was simply no-op. If you

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-13 Thread Albert Y. C. Lai
Brandon Michael Moore wrote: Calling hClose after hGetContents is the root of the problem, but this is a good example for understanding seq better too. To further this end, I'll take issue :) with the final version that has been tested to work, and show that it still won't work. First, the

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-13 Thread Michael Vanier
Albert, Thanks for the very detailed reply! That's the great thing about this mailing list. I find your description of seq somewhat disturbing. Is this behavior documented in the API? I can't find it there. It suggests that perhaps there should be a

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-13 Thread Stefan O'Rear
On Fri, Jul 13, 2007 at 04:29:12PM -0700, Michael Vanier wrote: Albert, Thanks for the very detailed reply! That's the great thing about this mailing list. I find your description of seq somewhat disturbing. Is this behavior documented in the API? I can't find it there. It suggests

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-13 Thread Felipe Almeida Lessa
On 7/13/07, Stefan O'Rear [EMAIL PROTECTED] wrote: instance Eval Int where ... seq (-1) b = b seq 0 b = b seq 1 b = b ... I don't think you need all these cases. In fact, you can write instance Eval Int where seq 0 b = b seq _ b = b which, in GHC -O2, desugars to

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-13 Thread Michael Vanier
Stefan, Thanks for your comments, as always. What I meant by really-truly-absolutely-I-mean-right-now-seq is something that would evaluate its argument as far as it is possible to do so i.e. something that forces strict evaluation of an argument. That's what I thought seq did, but now I see

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-13 Thread Daniel McAllansmith
On Saturday 14 July 2007 11:29, Michael Vanier wrote: Albert, Thanks for the very detailed reply! That's the great thing about this mailing list. I find your description of seq somewhat disturbing. Is this behavior documented in the API? I can't find it there. As I understand it seq

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-13 Thread Tim Chevalier
On 7/13/07, Michael Vanier [EMAIL PROTECTED] wrote: Stefan, Thanks for your comments, as always. What I meant by really-truly-absolutely-I-mean-right-now-seq is something that would evaluate its argument as far as it is possible to do so i.e. something that forces strict evaluation of an

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-13 Thread Felipe Almeida Lessa
On 7/13/07, Michael Vanier [EMAIL PROTECTED] wrote: What I meant by really-truly-absolutely-I-mean-right-now-seq is something that would evaluate its argument as far as it is possible to do so i.e. something that forces strict evaluation of an argument. What you want is to reduce something

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-13 Thread Derek Elkins
On Fri, 2007-07-13 at 17:20 -0700, Michael Vanier wrote: Stefan, Thanks for your comments, as always. What I meant by really-truly-absolutely-I-mean-right-now-seq is something that would evaluate its argument as far as it is possible to do so i.e. something that forces strict

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-13 Thread Stefan O'Rear
On Fri, Jul 13, 2007 at 09:19:58PM -0300, Felipe Almeida Lessa wrote: On 7/13/07, Stefan O'Rear [EMAIL PROTECTED] wrote: instance Eval Int where ... seq (-1) b = b seq 0 b = b seq 1 b = b ... I don't think you need all these cases. In fact, you can write instance

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-12 Thread Michael Vanier
That makes sense. Thanks! Mike Stefan O'Rear wrote: On Thu, Jul 12, 2007 at 09:22:09PM -0700, Michael Vanier wrote: I stumbled across a problem with IO and strictness that I could fix, but I can't understand why the fix works. I've compressed it down into a program which simply computes

Re: [Haskell-cafe] problem with IO, strictness, and let

2007-07-12 Thread Stefan O'Rear
On Thu, Jul 12, 2007 at 09:22:09PM -0700, Michael Vanier wrote: I stumbled across a problem with IO and strictness that I could fix, but I can't understand why the fix works. I've compressed it down into a program which simply computes the number of lines in a file. Here is a version that

[Haskell-cafe] problem with IO, strictness, and let

2007-07-12 Thread Michael Vanier
I stumbled across a problem with IO and strictness that I could fix, but I can't understand why the fix works. I've compressed it down into a program which simply computes the number of lines in a file. Here is a version that doesn't work: module Main where import System.IO import