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

Robert Virding robert.virding@REDACTED
Wed Apr 13 17:52:18 CEST 2011


The comparison operators as they are now were a mistake, almost a bad mistake. IMAO what we should have done was to have had two different sets of operators, one set of numeric comparisons (without type conversion) and one set of gerneral term comparisons (without type conversion). So for example:

== /= =< < >= >   would only work on numbers
@== @/= @=< @< @>= @>   would work on all terms

Note that the existing =:= =/= are the same as @== @/= in my scheme above.

We could add the full set of term comparison operators, but not change the existing operators to be only numeric comparison. The reaction if we did would be "interesting". :-)

Old sins cast long shadows.

Robert

----- "JohnyTex" <ekeroth.christoffer@REDACTED> wrote:

> 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
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list