[Haskell-cafe] coding standard question

Loup Vaillant loup.vaillant at gmail.com
Tue Jun 30 05:57:48 EDT 2009


2009/6/22 Malcolm Wallace <Malcolm.Wallace at cs.york.ac.uk>:
> Erik de Castro Lopo <mle+hs 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.
>
> Particularly in larger examples, it can be remarkably easy to miss an
> occurrence of the variable whose name you are refactoring.  The key
> point is that in this situation, unlike most refactorings, the compiler
> _cannot_ help you find the mistake with useful error messages or
> warnings.

What about an editor (or emacs mode or…) that support variable renaming?
Maybe there is already one?

Loup


More information about the Haskell-Cafe mailing list