Changes between Initial Version and Version 3 of Ticket #5858


Ignore:
Timestamp:
Feb 10, 2012 10:25:31 AM (2 years ago)
Author:
simonpj
Comment:

Here's why it your last example works: GHC infers this type for foo:

    foo :: forall t t1.
           (Data.String.IsString t1, Data.String.IsString t,
            InferOverloaded (Data, [(t, t1)])) =>
           (Data, [(t, t1)])

Notice that

  • There is nothing to force "overloaded" and "strings" to have the same type, so they get types t, t1 respectively.
  • Hence the instance does not get used
  • GHC instead defers solving the constraint to the call site, in the hope that it may by then be clearer what t, t1 are.

One way to get the un-annotated behaviour you want might be this:

instance (t1 ~ Text, t2 ~ Text) => InferOverloaded (Data, [(t1,t2)] where
  infer = id

About your suggestion about error messages, I suppose that in the situation where giving more type information at the call site would pick a valid instance, we could suggest that. I can see where to do this. Could you supply a small test case that exhibits the behaviour? (Not depending on Data.Text.)

Thanks

Simon

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #5858

    • Property Cc greg@… added
    • Property Difficulty changed from to Unknown
  • Ticket #5858 – Description

    initial v3  
    3434I would be ok with having to type annotate if instead of the compiler suggesting I declare an entire new instance the compiler instead suggested that I annotate my overloaded strings. 
    3535 
    36 However, in trying to reproduce this program in a simpler setting, it seems to normally perform the OverloadedStrings inference without any issue. This works just fine: 
     36However, in trying to reproduce this program in a simpler setting, it seems to normally perform the `OverloadedStrings` inference without any issue. This works just fine: 
    3737 
    3838{{{