Braces vs. Whitespace

Ashley Yakeley ashley@semantic.org
Tue, 21 Aug 2001 20:52:18 -0700


At 2001-08-21 20:31, Dean Herington wrote (on the Haskell list):

>Now realizing that the "where" keyword is optional when there are no
>accompanying declarations, I think it would be preferable to omit the
>"where" keyword to indicate that the absence of declarations is
>intentional.

Personally I prefer the explicit braces/semicolons syntax rather than 
worrying about whitespace:

module DeepSeq where
     {
     class DeepSeq a where
          {
          deepSeq :: a -> b -> b;
          deepSeq = seq;            -- default, for simple cases
          };

     ...

     instance DeepSeq Ordering;
     instance DeepSeq Integer;
     instance DeepSeq Int;
     instance DeepSeq Float;
     instance DeepSeq Double;
     }

...or if you prefer...

module DeepSeq where
{
     class DeepSeq a where
     {
          deepSeq :: a -> b -> b;
          deepSeq = seq;            -- default, for simple cases
     };

     ...

     instance DeepSeq Ordering;
     instance DeepSeq Integer;
     instance DeepSeq Int;
     instance DeepSeq Float;
     instance DeepSeq Double;
}

etc.

Basically you put a braced block after every 'do', 'in' and 'where', and 
semicolons after every declaration. When I was first learning Haskell, I 
got massively confused by the whitespace rules, especially with mixed 
tabs/spaces etc. I reckon the braces style is more readable to anyone 
used to C/C++/Java etc.

-- 
Ashley Yakeley, Seattle WA