It came out from Slack that record type errors still need some love. I think it would be useful to discuss here what’s the best direction to take.
There’s also this issue which should be addressed but which I wasn’t able to replicate.
I’m pasting some error expamples below to help the discussion.
A
a = [{ a: 1, b: 2 }, { a: 1 }]
Could not match type
( b :: Int
...
)
with type
( ... )
while trying to match type
( b :: Int
...
)
with type
( ... )
while inferring the type of [ { a: 1
, b: 2
}
, { a: 1
}
]
in value declaration a
B
b = [{ a: { b: 1 } }, { a: { c: 1 } }]
Could not match type
( b :: Int
...
)
with type
( c :: Int
...
)
while trying to match type
( b :: Int
...
)
with type
( c :: Int
...
)
while inferring the type of [ { a: { b: ...
}
}
, { a: { c: ...
}
}
]
in value declaration b
C
c = [{ a: 1, b: 2 }, {a : true, b: 2 }]
Could not match type
Int
with type
Boolean
while trying to match type
( a :: Int
...
)
with type
( a :: Boolean
...
)
while inferring the type of [ { a: 1
, b: 2
}
, { a: true
, b: 2
}
]
in value declaration c
Case A and B are basically the same, just with a different nesting level of the error. In both, the while trying to match type ... with type ...
is completely usess as it’s just a repetition of the Could not match type ... with type ...
part.
Case C shows different informations in the two sections, but it could be made similar to the first two cases by still showing the rows diff instead of just the labels’ types.
A possible solution would be to eliminate the second section of the error section, making for example the new error for A as:
Could not match type
( b :: Int
...
)
with type
( ... )
while inferring the type of [ { a: 1
, b: 2
}
, { a: 1
}
]
in value declaration a
I think the error is a bit cryptic for new users maybe. Would a partial rewording help? Maybe it could be good to make the error message more specific to records instead of using the same structure of the other type errors.