[erlang-questions] Lack of warning for overlapping clauses with

Torben Hoffmann <>
Wed Jul 21 00:24:02 CEST 2010


On Tue, Jul 20, 2010 at 23:53, Richard O'Keefe <> wrote:

>
> On Jul 20, 2010, at 8:12 PM, Torben Hoffmann wrote:
>
>  I have not tried this out in Haskel (or any other FP language) since I am
>> trying to keep my computer clean, ie, only Erlang and what that entails
>> ;-)
>> But I suspect that Haskel is capable of detecting this.
>>
>
> There are several Haskell compilers.
>
> Let's construct two little Haskell functions.
>
>   transparent 1 = False
>   transparent 2 = False
>   transparent 1 = True
>
>   opaque n | n == 1 || n == 2 = False
>   opaque 1                    = True
>
>   main = print (transparent 1, transparent 2, opaque 1, opaque 2)
>
> and see what Haskell makes of them.
>        f% ghci         # This is version 6.6.1
>        Prelude> :load test.hs
>        [1 of 1] Compiling Main             ( test.hs, interpreted )
>
>        test.hs:1:0:
>            Warning: Pattern match(es) are overlapped
>                     In the definition of `transparent': transparent 1 = ...
>        Ok, modules loaded: Main.
>
>        f% nhc98 test.hs
>        f% a.out
>        (False,False,False,False)
>
> So nhc98 was completely silent, and ghc 6.6.1 did notice the
> explicit pattern duplication but did *NOT* notice the duplication
> of a pattern in a guard, any more than Erlang did.
>
I stand corrected! Thanks for putting my assumptions to a timely death!!


>
> I can't construct an SML analogue, because SML has no guards.
>
> This is expecting far more cleverness from the Erlang system than
> I would expect people to expect.
>
> Well, I actually ran into a problem with this in a real program and it was
by sheer coincidence that I noticed the overlapping clauses, so I would have
liked the compiler to spot this.

Given the Haskel evidence it seems that the problem is even harder than I
imagined at first, so maybe I am expecting too much... expecting too much
becomes so natural when you work with Erlang.

This means that there are two or more actions to be taken on this:
1. Ask a bright person who is into type checking to look at this in his
thesis project.
2. Change my style of programming so that it stays within the bounds of what
the compiler will warn me about.
3. [Optional] Put some explanations/warnings in the Erlang documentation so
that people are not let astray like me.

Action 3 is probably very low priority since it seems to almost only me that
has had this problem.

Thanks for all the inputs!
Cheers,
Torben



-- 
http://www.linkedin.com/in/torbenhoffmann


More information about the erlang-questions mailing list