[Haskell-cafe] How to use "bracket" properly ?

Evan Laforge qdunkan at gmail.com
Mon Oct 19 15:49:57 EDT 2009

On Sun, Oct 18, 2009 at 11:50 PM, zaxis <z_axis at 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 very well. However, as i am used to C style so i want convert it
> into

In the long run it is probably easier to just get used to haskell
style.  Putting in fewer braces and semicolons will be the least of
the adjustments to make from C.

I've seen some brace-ful code out there (notably ghc) but it tends not
to be in C style even so, e.g. with leading ;s instead of trailing
ones.  Even though haskell style is already all over the map, using
layout and omitting the punctuation seems most widespread to me.  Or
maybe it's just my bias since I prefer that style myself.

It might be interesting to have a few "standard" styles documented,
not to try to enforce anything, but have a couple self-consistent
systems up there with rationale for otherwise undecided people to look
at.  E.g. after seeing the leading comma style around I tried it out
myself and eventually adopted it, even though it looked weird at
first.  But it was only after seeing code in that style and guessing
for myself why it was that way.

More information about the Haskell-Cafe mailing list