[erlang-questions] Trouble with Erlang's lenient comparisons

JohnyTex ekeroth.christoffer@REDACTED
Wed Apr 13 16:50:37 CEST 2011


What I meant was when you use lesser/greater than on two different
types, i.e. checking if a tuple is greater than an integer - sorry for
being unclear :)

Thanks again for your advice!


On 13 Apr, 15:54, Kostis Sagonas <kos...@REDACTED> wrote:
> JohnyTex wrote:
> > Thanks for the advice guys! I managed to get Dialyzer running and it
> > worked very nicely; it managed to spot some unreachable code right off
> > the bat :)
>
> > However, it doesn't seem to get the more insidious errors that arise
> > from comparing other types than was intended, i.e. accidentaly
> > comparing a string to an integer... but since it's completely valid
> > Erlang I guess it's not supposed to complain?
>
> The answer depends on the kind of comparison that is used.
>
> If by comparison you mean case expressions or direct matching as in
>
>     case String of
>       Integer -> ...
>     end
>
> or
>
>     String = Integer
>
> then dialyzer will report these to you as impossible matches.
>
> If by comparison you mean uses of =/=, <, ... then of course these are
> allowed in Erlang and of course dialyzer will not warn you that you are
> doing something wrong there. (*)
>
> Kostis
>
> (*) Though it will warn you that e.g. the 'false' clause is unreachable
> in something like:
>
>     case String =\= Integer of
>       true -> ...
>       false -> ...
>     end
> _______________________________________________
> erlang-questions mailing list
> erlang-questi...@REDACTED://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list