Understanding ambiguous overloading warning

30 views
Skip to first unread message

Gustavo Carvalho

unread,
Mar 30, 2022, 6:21:40 PM3/30/22
to gf-...@googlegroups.com
Hi,

When I try to compile the following example:

abstract Test = Cat ** {
  cat X ;
  fun mkQualifiedX : Cat.A -> X -> X ;
}

concrete TestC of Test = CatEng **
open SyntaxEng in {
  lincat X = CatEng.CN ;
  lin mkQualifiedX adj x = mkCN adj x ;
}

I get the following warning message:

TestC.gf:
   TestC.gf:4:
     Happened in linearization of mkQualifiedX
      Warning: ambiguous overloading of mkCN resolved by selecting the first of the alternatives
                 \x,y -> NounEng.AdjCN (AdjectiveEng.PositA x) (NounEng.UseN y)
                 \x,y -> NounEng.AdjCN (AdjectiveEng.PositA x) y

UseN promotes a noun to a CN, but in the context of mkQualifiedX its second argument is of type X (i.e., CN). Therefore, I was expecting that only the second alternative would be applicable (the second argument of mkQualifiedX is not a noun).

I would really appreciate it if someone could help me to understand this warning message and give me some hints on how to avoid it.

Thank you in advance.

Best regards,
Gustavo

Inari Listenmaa

unread,
Mar 30, 2022, 8:49:13 PM3/30/22
to Grammatical Framework
Hi Gustavo,

As for why these warnings happen, I direct you to this answer, talking about an old (now fixed) bug in GF's overloading: https://groups.google.com/g/gf-dev/c/0kiV9mSVk2Y/m/ZHMghxOnAwAJ 

[T]he system has a complexity that I don't know from any other programming language. It combines

- overloading based on static typing
   - also allowing disambiguation on the value type, which is more than usual
   - also allowing partial application of functions
- subtyping, in particular records
- type inference
  - but not for lambda expressions at the moment: this is the issue I met yesterday, and which appeared in a nested overloading in ParadigmsAra
  - the reason it does not work for lambda is that GF is not polymorphic: e.g. (\x -> x) can only be type-inferred in a polymorphic system

Unlike the "basic GF" type system (in the JFP article 2004), this system has not been formally specified, but grown organically by addition of things that turned out useful in practice. Hence it can be the case that a complete and sound system combining all these features is not even possible: some formal work is needed to verify this.

As for how to avoid this warning, the message contains further actions:

Some workarounds will perhaps always be needed to help overload resolution, and it is good to know the main ones

- type annotations of arguments of overloaded functions: <t : T>
- step-wise applications with local definitions, as in John's example TestRes.f5:  
  let r : R = f a b in r ** {s = c}   
instead of   
  f a b ** {s = c}

In your example grammar, type annotations to the arguments of the overloaded mkCN will make the warnings disappear.

    lin mkQualifiedX adj x = mkCN <adj : A> <x : CN> ;

But also, these warnings are pretty harmless, and I usually don't care about them, as long as the compilation succeeds. Sometimes I do run into cases where the GF compiler can't correctly resolve the overloading, and I only add type annotations in those cases. But of course, if you prefer to not have any warnings, you can add type annotations even when it only gives a warning.

If someone has more information on why specifically this case causes those warnings, please expand my answer! I just wanted to provide a quick answer on what to do about them.

Cheers,
Inari

--

---
You received this message because you are subscribed to the Google Groups "Grammatical Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gf-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gf-dev/CAL44rvZztqO6L1w9BJk-0iTWqXh7x6f%3Det24rJS_3eDQA_%2BfjQ%40mail.gmail.com.

Gustavo Carvalho

unread,
Mar 31, 2022, 5:05:03 PM3/31/22
to gf-...@googlegroups.com
Dear Inari,

Thank you for your quick and very informative response!
I managed to eliminate the warning with your suggestion. Thank you!

Best regards,
Gustavo

Reply all
Reply to author
Forward
0 new messages