[Haskell-cafe] Re: About code style ?

Ertugrul Soeylemez es at ertes.de
Tue Feb 2 01:51:40 EST 2010

Hello zaxis,

as others have noted, you are trying to write C in Haskell.  Well, that
gains you nothing and rather gets you into trouble.  If you want to
write C, then use instead and not Haskell, because the idioms you're
used to in C will not work at all in Haskell.  Note for example that the
'do' keyword is misleading.  It does not introduce imperative code, but
monadic code, which may well be pure.

To answer your question:  There are no blocks in Haskell, which you
could put into braces.  Don't think in blocks of code, because that is
C, not Haskell, and it's plain wrong.  You are not going to write any
for/while loops anyway.  Thinking that way may have a negative impact on
your Haskell coding style.  The only place where braces are used is
record types and many Haskell programmers (including me) consider this
an ugly syntax.

But don't worry, you'll get used to the new syntax and eventually fall
in love with it, because it will make your life easier.  I myself came
from years of C/C++ experience and had similar difficulties in the


zaxis <z_axis at 163.com> wrote:

> For me i like C style instead of layout. For example, 
> func1 a = do
>      -- ...
>      a * 2
>      -- ...
> I always write it as:
> func1 a = do {
>   -- ...;
>    a * 2;
>   -- ...;
> }
> However, i donot know how to write pure function using C style.
> func1 a = {
>   -- ...;
>    a * 2;
>   -- ...;
> }
> will not compile without `do`.
> Sincerely!
> -----
> fac n = foldr (*) 1 [1..n]

nightmare = unsafePerformIO (getWrongWife >>= sex)

More information about the Haskell-Cafe mailing list