Wizek
Wizek

Reputation: 4993

What does a Haskell type error mean when it includes: "... is as general as its inferred signature ..."?

Edit: @luqui is onto something, with a much simpler reproducible case in GHCi:

Prelude> let (a, b) = ('x', return 'y')

<interactive>:1:5: error:
    * Ambiguous type variable `m0'
      prevents the constraint `(Monad m0)' from being solved.
    * When checking that the inferred type
        a :: forall (m :: * -> *). Monad m => Char
      is as general as its inferred signature
        a :: Char

But then how come all the following variants work?

Prelude> let c = ('x', return 'y')
Prelude> :t c
c :: Monad m => (Char, m Char)
Prelude> let d = 'x'; e = return 'y'
Prelude> :t d
d :: Char
Prelude> :t e
e :: Monad m => m Char
Prelude> :t (d, e)
(d, e) :: Monad m => (Char, m Char)
Prelude>

Shouldn't all of these work the same way?


Original question:

Here is a specific example:

• Ambiguous type variable ‘m0’
  prevents the constraint ‘(Monad m0)’ from being solved.

• When checking that the inferred type
    logger :: forall b t (m :: * -> *).
              Monad m =>
              Data.Text.Internal.Text -> IO ()
  is as general as its inferred signature
    logger :: Data.Text.Internal.Text -> IO ()

And here is some background information and some instructions to reproduce the error in the above specific case.

But I'm curious even in the general case: under what circumstances can this error arise, and what is it trying to convey?

Upvotes: 1

Views: 143

Answers (1)

dfeuer
dfeuer

Reputation: 48581

I believe the problem is that you're using a pattern binding.

(a, b) = ('x', return 'y')

basically does this

ab = ('x', return 'y')
a = fst ab
b = snd ab

The type of ab is

ab :: Monad m => (Char, m Char)

so a has type

a :: Monad m => Char

What is m? It doesn't appear to the right of the =>, so it's ambiguous.

Upvotes: 2

Related Questions