Skip to content

default Int is ignored for argument of levity polymorphic method

See also: #25778 (closed)

Summary

test/Debug/TraceIf/Test/TraceIf/TH.hs:46:25: error: [GHC-43085]
    • Overlapping instances for Show t0 arising from a use of ‘show’
      Matching instance:
        instance P.Show a => Show a
          -- Defined at test/Debug/TraceIf/Test/TraceIf/TH.hs:35:10
      Potentially matching instance:
        instance Show (ShowTrace ())
          -- Defined at test/Debug/TraceIf/Test/TraceIf/TH.hs:38:10
      (The choice depends on the instantiation of ‘t0’
       To pick the first instance above, use IncoherentInstances
       when compiling the other instance declarations)
    • In the second argument of ‘(==)’, namely ‘show 1’
      In the expression: "1" == show 1
      In an equation for ‘unit_svarsWith’: unit_svarsWith = "1" == show 1
   |
46 | unit_svarsWith = "1" == show 1
   |                         ^^^^

test/Debug/TraceIf/Test/TraceIf/TH.hs:46:30: error: [GHC-39999]
    • Ambiguous type variable ‘t0’ arising from the literal ‘1’
      prevents the constraint ‘(Num t0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘t0’ should be.
      Potentially matching instances:
        instance Num Integer
          -- Defined in ‘ghc-internal-9.1001.0:GHC.Internal.Num’
        instance Num Double
          -- Defined in ‘ghc-internal-9.1001.0:GHC.Internal.Float’
        ...plus three others
        ...plus one instance involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the first argument of ‘show’, namely ‘1’
      In the second argument of ‘(==)’, namely ‘show 1’
      In the expression: "1" == show 1
   |
46 | unit_svarsWith = "1" == show 1

Steps to reproduce

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
module Debug.TraceIf.Test.TraceIf.TH where

import GHC.Exts
import Prelude hiding (Show (..))
import Prelude qualified as P

default (Int)

class Show (t :: TYPE r) where
  show :: t -> String

newtype ShowTrace a = ShowTrace { unShowTrace :: a }

instance P.Show a => Show a where
  show = P.show

instance Show (ShowTrace ()) where
  show (ShowTrace ()) = "()"

unit_svarsWith :: Bool
unit_svarsWith = "1" == show 1

Expected behavior

Literal argument of show (1) should be typed as Int because of default (Int).

Show (ShowTrace ()) as a candidate looks wrong. ShowTrace () does not have Num instance.

Environment

  • GHC version used: 9.10.1

Optional:

  • Operating System: Linux
  • System Architecture: x86_64
Edited by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information