For example, Time is an alias for Float, but the compiler reports these as different types.
SSCCE:
import Time exposing (Time)
type alias Model =
{ a : Int
, b : Time
, c : Int
}
update : Model -> Model
update model =
if True then
{ model | b = 1.0 }
else
{ model | a = "Hey" }
-- TYPE MISMATCH ---------------------------------------------------------------
The branches of this `if` produce different types of values.
17|> if True then
18|> { model | b = 1.0 }
19|> else
20|> { model | a = "Hey" }
The `then` branch has type:
{ ..., a : Int, b : Float }
But the `else` branch is:
{ ..., a : String, b : Time }
Hint: Problem in the `a` field. I always figure out field types in alphabetical
order. If a field seems fine, I assume it is "correct" in subsequent checks. So
the problem may actually be a weird interaction with previous fields.
Hint: These need to match so that no matter which branch we take, we always get
back the same type of value.
In this case, a is the cause of this error but the compiler also show b as a difference. b is colored on console. The image below is another example that happened in my project. Float <-> Time and Msg <-> msg is unnecessary information.
For example,
Time
is an alias forFloat
, but the compiler reports these as different types.SSCCE:
In this case,
a
is the cause of this error but the compiler also showb
as a difference.b
is colored on console. The image below is another example that happened in my project.Float
<->Time
andMsg
<->msg
is unnecessary information.Elm: 0.18