Skip to content

Commit

Permalink
GHC-39999: add missing quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim authored Jun 1, 2024
1 parent 2a30eea commit 2c2122a
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ Main.hs:1:16: error: [GHC-39999]

Given that Haskell is a strong statically typed language, it is not a surprise that adding numbers to strings gives a compile-time error. However, one could expect GHC to be unhappy about `"4"`, not about `5` as above! Let's take a deeper look on how the type checker works.

The compiler first encounters the operator `(+)` which has type `Num a => a -> a -> a`. Thus it infers that both arguments of `(+)` should be of the same type `a`. Looking at the first argument `5` does not reveal us what `a` is: it could be `Int`, could be `Double`, etc. But the second argument `4` is certainly `String`, so the compiler concludes that `a` should be `String`.
The compiler first encounters the operator `(+)` which has type `Num a => a -> a -> a`. Thus it infers that both arguments of `(+)` should be of the same type `a`. Looking at the first argument `5` does not reveal us what `a` is: it could be `Int`, could be `Double`, etc. But the second argument `"4"` is certainly `String`, so the compiler concludes that `a` should be `String`.

Now the compiler looks again at the first argument `5`. Since the second argument of `(+)` is `String`, it infers that `5` must be `String` as well. In Haskell a numeric literal could be anything which has `instance Num`, so GHC searches for `instance Num String` but could not find one and bails out with an error.

0 comments on commit 2c2122a

Please sign in to comment.