oversized source range in type error message
For this code
type Foo = Bool
type Bar = String
data Pair a b = Pair a b
baz :: Pair Foo Bar
baz = Pair "yes" "no"
ghc says
B.hs:7:7-21: error:
• Couldn't match type ‘[Char]’ with ‘Bool’
Expected type: Pair Foo Bar
Actual type: Pair [Char] [Char]
• In the expression: Pair "yes" "no"
In an equation for ‘baz’: baz = Pair "yes" "no"
|
7 | baz = Pair "yes" "no"
| ^^^^^^^^^^^^^^^
So, which argument is wrong?
In fact, how many are?
baz :: Pair Foo Bar
baz = Pair "yes" ()
B.hs:7:7-19: error:
• Couldn't match type ‘[Char]’ with ‘Bool’
Expected type: Pair Foo Bar
Actual type: Pair [Char] ()
• In the expression: Pair "yes" ()
In an equation for ‘baz’: baz = Pair "yes" ()
|
7 | baz = Pair "yes" ()
| ^^^^^^^^^^^^^
The following case works better (it shows that the first argument is the problem). What's the difference?
foo :: (Foo,Bar)
foo = ("yes", "no")
B.hs:11:8-12: error:
• Couldn't match type ‘[Char]’ with ‘Bool’
Expected type: Foo
Actual type: [Char]
• In the expression: "yes"
In the expression: ("yes", "no")
In an equation for ‘foo’: foo = ("yes", "no")
|
11 | foo = ("yes", "no")
| ^^^^^