Skip to content

Instantly share code, notes, and snippets.

@paulp
Last active March 31, 2017 00:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulp/71fa03ad85917f5fa02a3e8acbc98409 to your computer and use it in GitHub Desktop.
Save paulp/71fa03ad85917f5fa02a3e8acbc98409 to your computer and use it in GitHub Desktop.
different behavior between typelevel and standard compiler
/** The following difference in behavior is seen between the
* typelevel scala 2.12.1 compiler and the standard one. The
* only difference between the failing case and the succeeding one
* is the scalaOrganization. No compiler options are needed.
* To reproduce, add
*
* scalaOrganization := "org.typelevel"
*
* to the build.sbt at https://github.com/paulp/psp-std and sbt test.
*/
// This test case fails because typelevel chooses a less specific Show instance.
showsAs("[1..3]", 1 nthTo 3)
// Trying to pass the show instance which the standard compiler chooses shows why.
showsAs("[1..3]", 1 nthTo 3)(showConsecutive)
[error] /g/psp-std/std/src/test/scala/tests/MiscSpec.scala:81: type mismatch;
[error] found : psp.std.Show[psp.std.Consecutive[_ <: Singleton]]
[error] required: psp.std.Show[psp.std.all.ClosedRange[psp.std.Nth]]
[error] (which expands to) psp.std.Show[psp.std.Consecutive.Closed[psp.std.Nth]]
[error] showsAs("[1..3]", 1 nthTo 3)(showConsecutive),
[error] ^
// However if I pass type arguments to showConsecutive, typelevel
// is ok and the test passes.
showsAs("[1..3]", 1 nthTo 3)(showConsecutive[Nth, ClosedRange])
// Here's the definition of showConsecutive, complete with ominous comment.
/** Simpler versions of this method signature lead to implicit ambiguity.
*/
implicit def showConsecutive[A, CC[X] <: Consecutive[X]] : Show[CC[_ <: A]] = by(_.in)
/**** So... Where's the Singleton bound coming from? ****/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment