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

Torben Hoffmann <>
Tue Jul 20 10:12:26 CEST 2010


I am afraid that Bernard is right - there is no difference... neither erlc
or Dialyzer picks it up.

I would like to hear from the OTP team and/or the Dialyzer team to
understand what is cooking here.

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.

Cheers,
Torben

On Mon, Jul 19, 2010 at 08:34, Bernard Duggan <> wrote:

> You're right, but the catch is that your second example doesn't produce a
> warning either.  There may, of course, be a very good reason that these
> cases don't do so, but the difference between == and =:= is not it.
>
> B
>
>
> On 19/07/10 16:17, Hynek Vychodil wrote:
>
>> f(N) when N==1; N==2 ->
>>    false;
>> f(1) ->
>>    ok.
>>
>> is not same as
>>
>> f(1) ->
>>    false;
>> f(2) ->
>>    false;
>> f(1) ->
>>    ok.
>>
>> Following is:
>>
>> f(N) when N=:=1; N=:=2 ->
>>    false;
>> f(1) ->
>>    ok.
>>
>> Former is hard to realize for compiler even it is possible.
>>
>> On Thu, Jul 15, 2010 at 1:31 PM, Torben Hoffmann
>> <>  wrote:
>>
>>
>>> Hi,
>>>
>>> I had a very large module where I could not figure out why a specific
>>> thing
>>> was not happening and it turned out that the root of the problem was a
>>> construct like the following:
>>>
>>> -module(problem).
>>>
>>> -compile(export_all).
>>>
>>> f(N) when N==1; N==2 ->
>>>    false;
>>> f(1) ->
>>>    ok.
>>>
>>> I would have hoped that the compiler or dialyzer would have caught that
>>> the
>>> f(1) clause will never be executed, but that is not the case.
>>> It seems that the use of the when-clause changes the game so that the
>>> overlap is not detected.
>>> I accept that I am shooting myself in the foot here, but I would have
>>> liked
>>> to be helped by the compiler or dialyzer since figuring this one out
>>> after
>>> going through hefty logs is not fun.
>>>
>>> Now that I know this I can work around it, but it would be nice to get
>>> the
>>> warning since the code in my f(N) branch is actually not that small. Of
>>> course I could create a function to do the operation and rewrite like
>>> this:
>>>
>>> -module(problem).
>>>
>>> -compile(export_all).
>>>
>>> f(1) ->
>>>    g();
>>> f(2) ->
>>>    g();
>>> f(1) ->
>>>    ok.
>>>
>>> In which case the compiler will warn me about the overlap, but I find
>>> that
>>> to be somewhat ugly.
>>>
>>> Any comments on this?
>>>
>>> Cheers,
>>> Torben
>>> --
>>> http://www.linkedin.com/in/torbenhoffmann
>>>
>>>
>>>
>>
>>
>>
>>
>
>


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


More information about the erlang-questions mailing list