<div><div dir="auto">Transferring from <div><a href="https://mail.haskell.org/pipermail/haskell-prime/2018-October/004396.html">https://mail.haskell.org/pipermail/haskell-prime/2018-October/004396.html</a></div></div></div><div><br><div class="gmail_quote"><div dir="ltr">On Sat, 13 Oct 2018 at 4:04 AM, <<a href="mailto:camarao@dcc.ufmg.br">camarao@dcc.ufmg.br</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
       Consider for example:<br>
<br>
       class F a b where f:: a → b<br>
       class X a   where x:: a<br>
       fx = f x<br>
<br>
       The type of fx, (F a b, X a) ⇒ b, should not be ambiguous: in<br>
       distinct contexts, fx can have distinct types (if ambiguity, and<br>
       'improvement', are as defined below).</blockquote><div dir="auto"><br></div><div dir="auto">[See the -prime message for the "defined below".]</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">I'm just not seeing why you think any Haskell should accept that. What value could inhabit `fx` except bottom?</div><div dir="auto"><br></div><div dir="auto">And indeed no Haskell does accept it, not even GHC with all sorts of nasty extensions switched on, including `AllowAmbiguousTypes`.</div><div dir="auto"><br></div><div dir="auto">GHC will accept class `F` with a Functional Dependency `b -> a`, but still I can't 'poke' any value into the `x` argument to `f` in the equation for `fx`.</div><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Note: agreeing with this view can lead to far-reaching consequences, e.g. support of<br>
       overloaded record fields [1,Section 7], ...</blockquote><div dir="auto"><br></div><div dir="auto">There are other ways to support overloaded/duplicate record fields, without doing this much violence to the type system. Look at the `HasField` class using Functional Dependencies, in Adam Gundry's work.</div><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">polymonads [2] etc.<br>
</blockquote><div dir="auto"><br></div><div dir="auto">Note that's from a Trac ticket asking for 'dysfunctional' Functional Dependencies. There's a long discussion from the type-inference brains trust coming to no discernable conclusion as to whether it's broken type safety. (Catching incoherence in the Core lint typecheck is not a good look.)</div><div dir="auto"><br></div><div dir="auto">a) You've not shown any detailed working of how your proposal gives the type improvement required</div><div dir="auto">   without also descending into incoherence.</div><div dir="auto"><br></div><div dir="auto">b) The combination of Functional Dependencies+Overlapping Instances+Undecidable Instances might be able to cover just enough,</div><div dir="auto">   but not too much of the requirements (which were never made clear).</div><div dir="auto">   See my worked examples on that ticket -- some of which are really quite scary.</div><div dir="auto">   See some of Oleg's work on his ftp site with multi-directional FunDeps and overlaps to achieve injectivity.</div><div dir="auto">   To try to tame the scariness while still supporting enough power, see the suggestion here <div><a href="https://ghc.haskell.org/trac/ghc/ticket/15632">https://ghc.haskell.org/trac/ghc/ticket/15632</a></div></div><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
       Further examples can be discussed</blockquote><div dir="auto"><br></div><div dir="auto">I have yet to see a convincing use case (from the very lengthy discussions) which couldn't be handled already in GHC. I agree the combination of extensions in GHC (including its bogus consistency check/Trac #10675) can give alarming surprises; but they don't quite break type safety.</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> but this example conveys the<br>
       main idea that ambiguity should be changed; unlike the example<br>
       of (show . read), no type annotation can avoid ambiguity of<br>
       polymorphic fx in current Haskell.</blockquote><div dir="auto"><br></div><div dir="auto">Since `fx` is not accepted in current Haskell, whether you can put a type annotation seems beside the point.</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">AntC</div><div dir="auto"><br></div><div dir="auto"><pre style="white-space:pre-wrap;background-color:rgb(255,255,255)">[1]  Optional Type Classes for Haskell,
      Rodrigo Ribeiro, Carlos Camarão, Lucília Figueiredo, Cristiano 
Vasconcellos,
      SBLP'2016 (20th Brazilian Symposium on Programming Languages),
      Marília, SP, September 19-23, 2016.

[2]  
<a href="https://github.com/carlos1camarao/ghc-proposals/blob/d81c1f26298961ac635ce0724bb76164b418866b/expression-ambiguity.rst">https://github.com/carlos1camarao/ghc-proposals/blob/d81c1f26298961ac635ce0724bb76164b418866b/expression-ambiguity.rst</a>
</pre><div dir="auto"><br></div></div></div></div>