Re: scalac does not infer super types when implicit for super type exists.

Stephen Compall <[email protected]>
Newsgroups gmane.comp.lang.scala
Message-ID <[email protected]>
On Sun, 2015-03-15 at 15:01 -0700, Jonathan Chayat wrote:
> def foo[T](x : T)(implicit ev: R[T]) = 0
> 
> println(foo(new B(1))) // infers T as B and fails to find implicit R[B]
> 
> println(foo(new B(1) : A)) // Works, but undesirable
> 
> 
> IMO, this seriously undermines usage of subtyping to encode
> co-products, which is very idiomatic in scala.


It undermines it, but not seriously. In most cases in non-test code, you
don't statically know which data constructor of the ADT you have in hand
anyway.


> I would like to propose the following change to type
> inference/implicit resolution: 
> When trying to infer a type T which appears in some implicit
> parameter, the compiler should successivelt try inferring supertypes
> of the type it starts from only failing if it reaches Any without
> finding suitable implicits.
> 
> In my opinion, this should not violate any type system rules, given
> that all type rules must still be satisfied. I could always add type
> annotations which make things work - so there is no correctness
> problem here.  
> 
> I understand that this is not a formal enough definition, but my goal
> here is to start a discussion of this issue.


Any solution to the problem you describe must satisfactorily address the
various concerns raised in this very argumentative thread about this
issue. Specifically regarding your proposal, you must also deal with the
fact that there may be no unambiguous or finite linearization of
supertypes of a given type to try.

-- 
Stephen Compall
"^aCollection allSatisfy: [:each|aCondition]": less is better

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
signature.asc (application/pgp-signature, 181 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEABECAAYFAlUM7uUACgkQYWjD35Pp0wIseACdFuCXxmOP6YMCyeNIKoSwxYt7
J80An2HXkPn96/vvkqUJxRla2QecdLxJ
=0SQs
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.