-
Notifications
You must be signed in to change notification settings - Fork 128
Description
Here's an example of a program with a type error:
f : {n} (fin n) => {a : [n]([n][2*n], [3*n]), b : [5*n]} -> [5*n]
f x = x.b
g : {a : [4]([3][8], [12]), b : [20]} -> [20]
g y = f y
And here's the type error message:
[error] at foo.cry:5:9--5:10:
Type mismatch:
Expected type: 4
Inferred type: 3
When checking type of function argument
There is a lot of information missing from this error message that the user needs to reconstruct in order to be able to understand the problem. From the source location you can tell that it's referring to the y in the rhs of g, which is an argument to f. It says the "expected type" is 4, but no 4 appears in the type signature for f. So to understand the error, the user needs to unify the result type [20] of g with the result type [5*n] of f, and then instantiate n = 4. Then the user needs to match the argument types together to discover that the length parameter of the 0th tuple field of the element type of the a field doesn't match.
A more informative type error message would help. GHC's type error messages have lots of useful information: Not just the inner types that don't match, but also the expected and actual types, as well as the expressions themselves.
Prelude> map fromInteger "abcdef"
<interactive>:5:17: error:
• Couldn't match type ‘Char’ with ‘Integer’
Expected type: [Integer]
Actual type: [Char]
• In the second argument of ‘map’, namely ‘"abcdef"’
In the expression: map fromInteger "abcdef"
In an equation for ‘it’: it = map fromInteger "abcdef"
We should do something more like this.