[erlang-questions] Trouble with Erlang's lenient comparisons
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.
----- "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
> 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
> > > worked very nicely; it managed to spot some unreachable code right
> > > the bat :)
> > > However, it doesn't seem to get the more insidious errors that
> > > from comparing other types than was intended, i.e. accidentaly
> > > comparing a string to an integer... but since it's completely
> > > 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
> > allowed in Erlang and of course dialyzer will not warn you that you
> > doing something wrong there. (*)
> > Kostis
> > (*) Though it will warn you that e.g. the 'false' clause is
> > in something like:
> > case String =\= Integer of
> > true -> ...
> > false -> ...
> > end
> > _______________________________________________
> > erlang-questions mailing list
> erlang-questions mailing list
More information about the erlang-questions