Skip to content

Defaulting is not consistent between GHC and GHCi?

Summary

As I understand the documentation for ExtendedDefaultRules, defaulting should behave the same in GHCi and GHC after turning on -XExtendedDefaultRules in GHC. Yet, the following function

main = let x = read "3" in print (x :: Int, x :: Double)

typechecks and works in GHCi but does not typecheck in GHC with -XExtendedDefaultRules. Is it not defaulting that is in play here or the documentation is wrong?

Steps to reproduce

{-#LANGUAGE ExtendedDefaultRules #-}
 
main = let x = read "3" in print (x :: Int, x :: Double)

Gives

    • Couldn't match expected type ‘Double’ with actual type ‘Int’
    • In the expression: x :: Double
      In the first argument of ‘print’, namely ‘(x :: Int, x :: Double)’
      In the expression: print (x :: Int, x :: Double)
  |
3 |  main = let x = read "3" in print (x :: Int, x :: Double)
  |                                              ^

Expected behavior

I expect the above program to pass typechecking in GHC because it does so in GHCi.

Environment

  • GHC version used: 8.8.1

Optional:

  • Operating System: Linux
  • System Architecture: x86-64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information