Re: formatting and guarded expressions

Malcolm Wallace <[email protected]> Thu, 23 Mar 2006 15:20:40 +0000
Newsgroups gmane.comp.lang.haskell.hugs.user
Organization Dept of Computer Science, University of York
Message-ID <[email protected]>
Wittie <[email protected]> wrote:

> >fact n
> >     | n == 0 = 1
> >     | otherwise = n * (fact(n-1))
> 
> Hugs complains about an unexpected ;
> 
> Sometimes code after a guarded expression fixes the problem. We've
> tried putting the | up against the > or underneath the parameter. The
> same code seems to work for some students but not for others.

I would guess that it fails when there is a mixture of tabs and spaces
before the different guards.  Haskell insists that tabs are 8 chars
wide, but many editors are configured to display tabs as 2 or 4 chars
wide.  Hence, code that looks in correct vertical alignment might well
be indented oddly as far as the compiler is concerned.

Regards,
    Malcolm