[Haskell-cafe] coding standard question
Johan Tibell
johan.tibell at gmail.com
Mon Jun 22 07:28:00 EDT 2009
On Mon, Jun 22, 2009 at 12:06 PM, Malcolm Wallace <
Malcolm.Wallace at cs.york.ac.uk> wrote:
> Erik de Castro Lopo <mle+hs at mega-nerd.com <mle%2Bhs at mega-nerd.com>> wrote:
>
> > Vasili I. Galchin wrote:
> >
> > > "where/let" functions use the
> > > same name for function parameters as the outer function and hence
> > > there is a "shadow" warning from the compiler.
> >
> > In Haskell there is an easy way around this. Variables can
> > be name a, a', a'' and so on. ...
> > ... its a good idea to fix these warnings.
>
> I would _strongly_ advise not to do that. By trying to silence the
> spurious warning about shadowing, there is enormous potential to
> introduce new bugs that were not there before.
>
> Example:
>
> f a b = g (a+b) (b-a)
> where g a c = a*c
>
> ghc warns that g's parameter a shadows the parameter to f. So we
> introduce a primed identifier to eliminate the warning:
>
> f a b = g (a+b) (b-a)
> where g a' c = a*c
>
> Now, no warnings! But, oops, this function does not do the same thing.
> We forgot to add a prime to all occurrences of a on the right-hand-side.
>
Actually there's a warning:
ghci> let f a b = g (a+b) (b-a) where g a' c = a*c
<interactive>:1:34: Warning: Defined but not used: `a''
Cheers,
Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090622/0250feda/attachment.html
More information about the Haskell-Cafe
mailing list