Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile time error blowups #1

Closed
danbst opened this issue May 11, 2014 · 1 comment
Closed

Compile time error blowups #1

danbst opened this issue May 11, 2014 · 1 comment

Comments

@danbst
Copy link

danbst commented May 11, 2014

When any compile time format inconsistences are found, GHC makes very large and scary type error. Not userfriendly way to say "your format string is incorrect":(

L> [s|Hello %05.2d world|] 100.12334

<interactive>:50:4:
    No instance for (Show a0)
      arising from a use of `Text.Printf.TH.showIntegral'
    The type variable `a0' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Show Double -- Defined in `GHC.Float'
      instance Show Float -- Defined in `GHC.Float'
      instance (Integral a, Show a) => Show (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
      ...plus 70 others
    In the first argument of `Data.String.fromString', namely
      `Text.Printf.TH.showIntegral
         (Text.Printf.TH.Chunk
            ((:) Text.Printf.TH.Zero [])
            (Just (Text.Printf.TH.Width 5))
            (Just (Text.Printf.TH.Precision 2))
            Text.Printf.TH.SignedDec)
         5
         2
         a_a2Fj'
    In the expression:
      Data.String.fromString
        (Text.Printf.TH.showIntegral
           (Text.Printf.TH.Chunk
              ((:) Text.Printf.TH.Zero [])
              (Just (Text.Printf.TH.Width 5))
              (Just (Text.Printf.TH.Precision 2))
              Text.Printf.TH.SignedDec)
           5
           2
           a_a2Fj)
    In the first argument of `Data.Monoid.mconcat', namely
      `["Hello ",
        Data.String.fromString
          (Text.Printf.TH.showIntegral
             (Text.Printf.TH.Chunk
                ((:) Text.Printf.TH.Zero [])
                (Just (Text.Printf.TH.Width 5))
                (Just (Text.Printf.TH.Precision 2))
                Text.Printf.TH.SignedDec)
             5
             2
             a_a2Fj),
        " world"]'

<interactive>:50:25:
    No instance for (Fractional a0)
      arising from the literal `100.12334'
    The type variable `a0' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Fractional Double -- Defined in `GHC.Float'
      instance Fractional Float -- Defined in `GHC.Float'
      instance Integral a => Fractional (GHC.Real.Ratio a)
        -- Defined in `GHC.Real'
    In the first argument of `\ a_a2Fj
                                -> id (Data.Monoid.mconcat ["Hello ", ....] :: S
tring)', namely
      `100.12334'
    In the expression:
      \ a_a2Fj
        -> id
             (Data.Monoid.mconcat
                ["Hello ",
                 Data.String.fromString
                   (Text.Printf.TH.showIntegral
                      (Text.Printf.TH.Chunk
                         ((:) Text.Printf.TH.Zero [])
                         (Just (Text.Printf.TH.Width 5))
                         (Just (Text.Printf.TH.Precision 2))
                         Text.Printf.TH.SignedDec)
                      5
                      2
                      a_a2Fj),
                 ....] ::
                String)
        100.12334
    In an equation for `it':
        it
          = \ a_a2Fj -> id (Data.Monoid.mconcat ["Hello ", ....] :: String)
              100.12334
@pikajude
Copy link
Owner

pikajude commented Feb 4, 2018

Unfortunately I don't think there's a good way to solve this unless you add a type signature to the first argument. The main issue here is that GHC emits two different error messages for the same snippet and this is exacerbated by what the splice expands to.

See:

$ let x :: Integral i => i -> String; x = show . toInteger
$ x 123.44

<interactive>:10:1: error:
    • Ambiguous type variable ‘i0’ arising from a use of ‘x’
      prevents the constraint ‘(Integral i0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘i0’ should be.
      These potential instances exist:
        instance Integral Integer -- Defined in ‘GHC.Real’
        instance Integral Int -- Defined in ‘GHC.Real’
        instance Integral Word -- Defined in ‘GHC.Real’
        ...plus four instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the expression: x 123.44
      In an equation for ‘it’: it = x 123.44

<interactive>:10:3: error:
    • Ambiguous type variable ‘i0’ arising from the literal ‘123.44’
      prevents the constraint ‘(Fractional i0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘i0’ should be.
      These potential instances exist:
        instance ∀ a. Fractional a ⇒ Fractional (Q a)
          -- Defined in ‘reflection-2.1.3:Data.Reflection’
        instance Fractional Double -- Defined in ‘GHC.Float’
        instance Fractional Float -- Defined in ‘GHC.Float’
        ...plus five instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the first argument of ‘x’, namely ‘123.44’
      In the expression: x 123.44
      In an equation for ‘it’: it = x 123.44

So there's not much that can be done here, unless you bind the formatting function to a name that GHC will use rather than expanding it.

@pikajude pikajude closed this as completed Feb 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants