Skip to content

Ambiguous type variable arising from fractional literal

This compiles

{-# LANGUAGE NoImplicitPrelude #-}

module Bug where

one = 1

this does not

{-# LANGUAGE NoImplicitPrelude #-}

module Bug where

pi = 3.1415
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

Bug.hs:5:6: error:
    • Ambiguous type variable ‘p0’ arising from the literal ‘3.1415’
      prevents the constraint ‘(GHC.Real.Fractional
                                  p0)’ from being solved.
      Relevant bindings include pi :: p0 (bound at Bug.hs:5:1)
      Probable fix: use a type annotation to specify what ‘p0’ should be.
      These potential instance exist:
        one instance involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the expression: 3.1415
      In an equation for ‘pi’: pi = 3.1415
  |
5 | pi = 3.1415
  |      ^^^^^^
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information