Re: [Haskell-cafe] How to use bracket properly ?

2009-10-21 Thread Henning Thielemann
zaxis schrieb: winSSQ count noRed noBlue = do { yesRed - [1..33] \\ noRed; yesBlue - [1..16] \\ noBlue; bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1); return () You might prefer 'withFile' or even better and if possible, write

Re: [Haskell-cafe] How to use bracket properly ?

2009-10-19 Thread zaxis
thanks for your quick answer. But winSSQ count noRed noBlue = do { let yesRed = [1..33] \\ noRed; let yesBlue = [1..16] \\ noBlue; bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1); } will report: parse error on input `let' Daniel Peebles

Re: [Haskell-cafe] How to use bracket properly ?

2009-10-19 Thread Thomas DuBuisson
thanks for your quick answer. But I think he actually answered your question. I.e. try it with this extra 'do' statement: winSSQ count noRed noBlue = do { do    let yesRed =  [1..33] \\ noRed;    let yesBlue = [1..16] \\ noBlue;    bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 -

Re: [Haskell-cafe] How to use bracket properly ?

2009-10-19 Thread zaxis
The original code is: winSSQ count noRed noBlue = do let yesRed = [1..33] \\ noRed let yesBlue = [1..16] \\ noBlue bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1) It works very well. However, as i am used to C style so i want convert it

Re: [Haskell-cafe] How to use bracket properly ?

2009-10-19 Thread Ketil Malde
zaxis z_a...@163.com writes: winSSQ count noRed noBlue = do let yesRed = [1..33] \\ noRed let yesBlue = [1..16] \\ noBlue bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1) It works very well. However, as i am used to C style so i want

Re: [Haskell-cafe] How to use bracket properly ?

2009-10-19 Thread Dougal Stanton
On Mon, Oct 19, 2009 at 9:18 AM, Ketil Malde ke...@malde.org wrote: zaxis z_a...@163.com writes: winSSQ count noRed noBlue = do     let yesRed =  [1..33] \\ noRed     let yesBlue = [1..16] \\ noBlue     bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue

Re: [Haskell-cafe] How to use bracket properly ?

2009-10-19 Thread Miguel Mitrofanov
Ketil Malde wrote: winSSQ count noRed noBlue = do { let yesRed = [1..33] \\ noRed; ^^^ ^ Didn't you just comment out your semicolons? That was my initial reaction. Until I remembered that Haskell has a different comment style.

Re: [Haskell-cafe] How to use bracket properly ?

2009-10-19 Thread Ketil Malde
Ketil Malde ke...@malde.org writes: Didn't you just ... Oh, dear. Sorry about that. -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] How to use bracket properly ?

2009-10-19 Thread zaxis
oh! thanks! But why ? Heinrich Apfelmus wrote: zaxis wrote: It works very well. However, as i am used to C style so i want convert it into winSSQ count noRed noBlue = do { let yesRed = [1..33] \\ noRed; let yesBlue = [1..16] \\ noBlue; bracket (openFile ssqNum.txt

Re: [Haskell-cafe] How to use bracket properly ?

2009-10-19 Thread Roel van Dijk
On Mon, Oct 19, 2009 at 1:44 PM, zaxis z_a...@163.com wrote: oh! thanks!  But why ? A let can introduce multiple declarations. So this foo = do let x = 3 let y = 4 return $ x+ y can also be written like foo = do let x = 3 y = 4 -- no let return $ x + y With explicit blocks:

Re: [Haskell-cafe] How to use bracket properly ?

2009-10-19 Thread Luke Palmer
On Mon, Oct 19, 2009 at 6:10 AM, Roel van Dijk vandijk.r...@gmail.com wrote: On Mon, Oct 19, 2009 at 1:44 PM, zaxis z_a...@163.com wrote: oh! thanks!  But why ? A let can introduce multiple declarations. So this foo = do  let x = 3  let y = 4  return $ x+ y can also be written like

Re: [Haskell-cafe] How to use bracket properly ?

2009-10-19 Thread Evan Laforge
On Sun, Oct 18, 2009 at 11:50 PM, zaxis z_a...@163.com wrote: The original code is: winSSQ count noRed noBlue = do    let yesRed =  [1..33] \\ noRed    let yesBlue = [1..16] \\ noBlue    bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1) It works

[Haskell-cafe] How to use bracket properly ?

2009-10-18 Thread zaxis
winSSQ count noRed noBlue = do { yesRed - [1..33] \\ noRed; yesBlue - [1..16] \\ noBlue; bracket (openFile ssqNum.txt WriteMode) (hClose) (\hd1 - pickSSQ count yesRed yesBlue hd1); return () } will report: Couldn't match expected type `IO ()' against inferred type `[()]' In a

Re: [Haskell-cafe] How to use bracket properly ?

2009-10-18 Thread Daniel Peebles
They're in different Monads. The first one does x - [...], which means that you're operating in the list Monad instance, and bracket operates in the IO Monad. The second one uses let x = [...] which doesn't have any effect on what Monad you're in, so the whole thing can be in IO. Note that when