Created
March 31, 2017 07:12
-
-
Save paulp/4ae0dc1aecbb48d1a20bbf9963777f87 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package p { | |
trait Show[-A] { | |
def show(x: A): String | |
} | |
trait Direct[+A] | |
trait Consecutive[+A] extends Direct[A] | |
final class Closed[+A]() extends Consecutive[A] | |
trait LowPriorityShow { | |
implicit def showDirect[A]: Show[Direct[A]] = | |
new Show[Direct[A]] { def show(x: Direct[A]) = "Direct[A]" } | |
} | |
object Run { | |
def main(args: Array[String]): Unit = { | |
println(showsAs(nrange(0, 3))) | |
} | |
} | |
} | |
package object p extends p.LowPriorityShow { | |
def nrange(s: Int, e: Int): Closed[Int] = new Closed[Int]() | |
def showsAs[A: Show](x: A): String = implicitly[Show[A]].show(x) | |
implicit def showConsecutive[A, CC[X] <: Consecutive[X]]: Show[CC[_ <: A]] = | |
new Show[CC[_ <: A]] { def show(x: CC[_ <: A]) = "CC[_ <: A]" } | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% ./run.sh | |
Typelevel... | |
Direct[A] | |
Scala... | |
CC[_ <: A] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
echo "Typelevel..." | |
CP="$(coursier fetch org.typelevel:scala-compiler:2.12.1 | paste -sd: -)" | |
rm -rf ./p | |
java -cp "$CP" scala.tools.nsc.Main -usejavacp -nowarn *.scala | |
java -cp "$CP" scala.tools.nsc.MainGenericRunner -usejavacp p.Run | |
echo "" | |
echo "Scala..." | |
rm -rf ./p | |
scalac-2.12 -nowarn *.scala | |
scala-2.12 p.Run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment