elm / error-message-catalog

A catalog of broken Elm programs / data to improve error messages
BSD 3-Clause "New" or "Revised" License
174 stars 17 forks source link

number doesn't seem to be comparable #182

Open gampleman opened 7 years ago

gampleman commented 7 years ago

This code:

range : number -> number -> number -> Bool
range start stop step =
   start + step > stop

causes this error on 0.18:

Detected errors in 1 module.

-- TYPE MISMATCH ---------------------------------------------------------------

The left argument of (>) is causing a type mismatch.

4|    start + step > stop
      ^^^^^^^^^^^^
(>) is expecting the left argument to be a:

    comparable

But the left argument is:

    number

Hint: Only ints, floats, chars, strings, lists, and tuples are comparable.

I would expect any number to be automatically comparable, so this error seems confusing.

gampleman commented 7 years ago

A workaround is

range : number -> number -> number -> Bool
range start stop step =
  let
    gtz n = 
       n > 0
  in
     gtz (start + step - stop)